Amazon I was reading http://docs.oracle.com/javase/tutorial/networking/nifs/parameters.html and decided to compile run the Java code listed on that webpage. Here is the code:
04 | import static java.lang.System.out; |
06 | public class ListNetsEx { |
08 | public static void main(String args[]) throws SocketException { |
09 | Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); |
10 | for (NetworkInterface netint : Collections.list(nets)) |
11 | displayInterfaceInformation(netint); |
14 | static void displayInterfaceInformation(NetworkInterface netint) throws SocketException { |
15 | out. printf ( "Display name: %s\n" , netint.getDisplayName()); |
16 | out. printf ( "Name: %s\n" , netint.getName()); |
17 | Enumeration<InetAddress> inetAddresses = netint.getInetAddresses(); |
19 | for (InetAddress inetAddress : Collections.list(inetAddresses)) { |
20 | out. printf ( "InetAddress: %s\n" , inetAddress); |
23 | out. printf ( "Up? %s\n" , netint.isUp()); |
24 | out. printf ( "Loopback? %s\n" , netint.isLoopback()); |
25 | out. printf ( "PointToPoint? %s\n" , netint.isPointToPoint()); |
26 | out. printf ( "Supports multicast? %s\n" , netint.supportsMulticast()); |
27 | out. printf ( "Virtual? %s\n" , netint.isVirtual()); |
28 | out. printf ( "Hardware address: %s\n" , |
29 | Arrays.toString(netint.getHardwareAddress())); |
30 | out. printf ( "MTU: %s\n" , netint.getMTU()); |
I happily compiled the code with
javac ListNetsEx.java and ran it with
java ListNetsEx. To my dismay I got the following error message:
Exception in thread "main" java.lang.UnsupportedClassVersionError: <your Java class name> :
Unsupported major.minor version 52.0
It turns out my Java JRE runtime environment is newer than the Java program. How do I fix the Java exception
java.lang.UnsupportedClassVersionError and
Unsupported major.minor version error?
Solution
I began to look for a solution on the Internet. Somewhere online I found a solution, which is run the following command :
javac -target 1.7 ListNetsEx.java
But then I got the following error:
javac: target release 1.7 conflicts with default source release 1.8
The
REAL solution is run the following command:
javac -target 1.7 -source 1.7 ListNetsEx.java
You will get a warning:
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
But it is harmless. Now run the following command:
java ListNetsEx
and you should see the output!
If it still doesn't work, try 1.6 instead of 1.7 in the command. If it still doesn't work, try 1.5. Try lowering the version number until it works.
Questions? Let me know!