Results 1 to 9 of 9
  1. #1
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default doesn't compile?!

    On Java API this is declared as

    Java 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]
    Last edited by jon80; 04-21-2008 at 09:51 PM. Reason: UPDATE 1 = UPDATING CODE TAGS

  2. #2
    bobleny's Avatar
    bobleny is offline Member
    Join Date
    Apr 2008
    Posts
    50
    Rep Power
    0

    Default

    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:
    Java Code:
    NetworkInterface ni = new NetworkInterface();
    NetworkInterface() doesn't exist to java. Have you created a NetworkInterface class?
    -- www.firemelt.net --
    Cheer up, the worst has yet to come...

  3. #3
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    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

  4. #4
    bobleny's Avatar
    bobleny is offline Member
    Join Date
    Apr 2008
    Posts
    50
    Rep Power
    0

    Default

    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....
    Java 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!
    -- www.firemelt.net --
    Cheer up, the worst has yet to come...

  5. #5
    rico16135 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

    Default

    NetworkInterface ni = new NetworkInterface();

    you can't instantiate a NetworkInterface that way.
    check here:
    What Is a Network Interface? (The Java™ Tutorials > Custom Networking > Programmatic Access to Network Parameters)

  6. #6
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    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.

  7. #7
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Thumbs down 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).

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    To use code tags, please place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:

    Java Code:
    &#91;code]
      // your code block goes here.
      // note the differences between the tag at the top vs the bottom.
    &#91;/code]

  9. #9
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    Java 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"));
    
    }

Similar Threads

  1. Compile Trouble
    By adelgado0723 in forum New To Java
    Replies: 5
    Last Post: 04-21-2008, 03:02 AM
  2. How to compile an applet to an exe
    By elizabeth in forum Java Applets
    Replies: 4
    Last Post: 02-18-2008, 04:57 AM
  3. Unable to compile
    By gapper in forum New To Java
    Replies: 2
    Last Post: 01-14-2008, 05:31 PM
  4. Not able to compile
    By bugger in forum New To Java
    Replies: 2
    Last Post: 01-09-2008, 11:13 PM
  5. compile error
    By dirtycash in forum New To Java
    Replies: 6
    Last Post: 12-12-2007, 07:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •