-
doesn't compile?!
On Java API this is declared as
Code:
public final class NetworkInterface
extends Object
Java Platform SE 6
Any idea why it does not compile?
[CODE]
*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package testone;
/**
* @author User
*/
import java.net.*;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
NetworkInterface ni = new NetworkInterface();
//Error:
//Compiling 1 source file to C:\Documents and Settings\User\My //Documents\NetBeansProjects\TestOne\build\classes
//C:\Documents and Settings\User\My //Documents\NetBeansProjects\TestOne\src\testone\Mai n.java:22: cannot //find symbol
//symbol : constructor NetworkInterface()
//location: class java.net.NetworkInterface
// java.net.NetworkInterface ni = new java.net.NetworkInterface();1 error
ni2 = java.net.NetworkInterface;
System.out.println(ni.getDisplayName());
}
}
[CODE]
-
The code tags don't work like that. You must use "[COD...]Your Code Here[/COD...]". Just replace the "..."s with an "E" so it says, "CODE".
The problem is, your calling an object that doesn't exist:
Code:
NetworkInterface ni = new NetworkInterface();
NetworkInterface() doesn't exist to java. Have you created a NetworkInterface class?
-
Thanks for that. NetworkInterface seems to be documented within the API:
java.net
Class NetworkInterface
java.lang.Object
extended by java.net.NetworkInterface
public final class NetworkInterface
extends Object
This class represents a Network Interface made up of a name, and a list of IP addresses assigned to this interface. It is used to identify the local interface on which a multicast group is joined. Interfaces are normally known by names such as "le0".
Since:
1.4
-
Oh, I better understand what your talking about now, but try as I might, I don't know how to help you.
This is as close as I can get... I have no idea what to do from here....
Code:
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
public class main
{
public static void main(String[] args) throws SocketException
{
Enumeration<NetworkInterface> ko = NetworkInterface.getNetworkInterfaces();
}
}
I hope someone else can help you. Good luck!
-
-
Yes, interfaces cannot be instantiated. I have seen them declared. Pretty much just to make some progress, try removing the new operator and see what the compiler tells you. Probably you will have to new some class that implements NetworkInterface, that restricts the use of the return from new to the methods declared in the interface.
This is very difficult for the beginner to understand because the books don't tell you that the entire existence of interface comes from large projects where people try to get their own ideas about what should happen. You have to have some way to tell them: "Now look, it works like this." and have them stick to that.
It just is not possible to stay on top of fifty people in different departments in different states trying to code in what they want, especially when some of them don't want to be programmers anyway.
-
doesn't compile?!
Well, I'm not sure why this is not compiling, because I was following the tutorial.
:confused:
[COD]
package testtwo;
/**
*
* @author user
*/
import java.net.*;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// IP and port make up a new socket
Socket soc1 = new Socket();
soc1.connect(java.net.InetSocketAddress("192.168.2 .100", "80"));
}
}
[/COD]
Error:
C:\Documents and Settings\User\Desktop\Main.java:16: cannot find symbol
symbol : class net
location: package java
soc1.connect(java.net.InetSocketAddress("192.168.2 .100", "80"));
^
1 error
Tool completed with exit code 1
I tried compiling it on WinXP SP2 and RH Fedora 8 (using NetBeans).
-
To use code tags, please place the tag [code] at the top of your block of code and the tag [/code] at the bottom, like so:
Code:
[code]
// your code block goes here.
// note the differences between the tag at the top vs the bottom.
[/code]
-
Code:
package testtwo;
/**
*
* @author user
*/
import java.net.*;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// IP and port make up a new socket
Socket soc1 = new Socket();
soc1.connect(java.net.InetSocketAddress("192.168.2 .100", "80"));
}