NetBeans Java Help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: NetBeans Java Help

  1. #1
    Join Date
    Oct 2009
    Posts
    2

    NetBeans Java Help

    Hi Guys,

    Working on a class at the moment in NetBeans however I have a problem with a section of code;

    Code:
        public void init() {
            itemList = new ArrayList();
            GUI gui1 = new GUI();
            getContentPane().add(gui1, "Center");
        }
    When built it brings up the following error;

    Code:
    NetBeansProjects\ToDoList\src\ToDoList.java:26: cannot find symbol
    symbol  : method add(ToDoList.GUI,java.lang.String)
    location: class java.awt.Container
            getContentPane().add(gui1, "Center");
    Note: Some input files use unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error
    I've included the full code below;

    Code:
    /* Small application implementing a To-Do List.
     * Uses a mobile phone-like interface.
     */
    
    import java.awt.Container;
    import java.util.ArrayList;
    import java.util.Collections;
    import javax.swing.JApplet;
    
    
    public class ToDoList extends JApplet {
    
        // first we create an instance of this class
        class GUI{}
    
        public ToDoList() {
    
    	    // create a graphical user interface,
                // passing it a reference to this tdl program object
                // initialisation goes here:
        }
    
        public void init() {
            itemList = new ArrayList();
            GUI gui1 = new GUI();
            getContentPane().add(gui1, "Center");
        }
    
        public ArrayList getList() {
    
            // dummy return value of an empty list,
            // just to get the program to compile initially
            return itemList;
        }
    
        public ArrayList addToList(String s) {
            itemList.add(s);
            return itemList;
    
        }
    
        public ArrayList getSortedList() {
    
            // dummy return value of an empty list,
            // just to get the program to compile initially
            Collections.sort(itemList);
            return itemList;
        }
    
        public ArrayList performReverse() {
    
            // dummy return value of an empty list,
            // just to get the program to compile initially
            Collections.reverse(itemList);
            return itemList;
        }
    
        public ArrayList performDeletion(int i) {
    
            // dummy return value of an empty list,
            // just to get the program to compile initially
            if(i < itemList.size())
                itemList.remove(i);
                        return itemList;
        }
    
        public ArrayList performSwap(int i) {
    
            // dummy return value of an empty list,
            // just to get the program to compile initially
            if(i < itemList.size() && itemList.size() >=2)
            {
                String s = (String)itemList.remove(i);
                if(i < itemList.size())
                    itemList.add(i + 1, s);
                else
                    itemList.add(itemList.size() - 1, s);
            }
            return itemList;
       }
    
        private GUI gui;
        private ArrayList itemList;
    }
    Suggestions would be appreciated!

  2. #2
    Join Date
    Aug 2009
    Posts
    5
    Hi,

    First of this problem has got nothing to do with NetBeans. Please use correct heading for the problem description.

    Coming to the compilation error, this is due to the reason that wrong method signature is being used here. The correct signature is:

    Code:
    add(String name, Component comp)
    So you can fix this error by using the above signature. Another important thing is that your GUI class should be of type
    Code:
    Component
    .

    For example :
    Code:
    class GUI extends Component {}
    Regards.

  3. #3
    Join Date
    Oct 2009
    Posts
    2
    Thanks for your reply. I have declared;

    Code:
    import java.awt.Component;
    and changed the troublesome block of code as follows;

    Code:
        public class GUI extends Component {
    
        public void init() {
            itemList = new ArrayList();
            GUI gui1 = new GUI();
            add(Component, gui1);
        }
    
        }
    The issue is still with add(Component, gui1); it has now underlined "Component" with the "cannot find symbol" error.

  4. #4
    Join Date
    Aug 2009
    Posts
    5
    Hi,

    Please pay attention to the method signature you are trying to use:

    Code:
    add(String name, Component comp)
    The first argument should be of type
    Code:
    java.lang.String
    for example: "Center".

    The second argument should be of type
    Code:
    java.awt.Component
    for example
    Code:
    class GUI extends Component
    .

    In your case the second argument is rightly specified as 'gui1', but its the first argument, which should be a String.

    Regards.

  5. #5
    Join Date
    Oct 2009
    Posts
    2
    Hi,

    Thanks for all your help, I'm very much a beginner with this! I seem to have fixed all the errors however now my applet just runs as a blank window, no graphic displayed.

    I've included all of the latest code below;

    ToDoList.java
    Code:
    /* Small application implementing a To-Do List.
     * Uses a mobile phone-like interface.
     */
    
    import java.lang.String;
    import java.awt.Component;
    import java.util.ArrayList;
    import java.util.Collections;
    import javax.swing.JApplet;
    
    public class ToDoList extends JApplet {
    
        // first we create an instance of this class
        public ToDoList() {
    
    	    // create a graphical user interface,
                // passing it a reference to this tdl program object
                // initialisation goes here:
        }
    
        class GUI extends Component {
    
        public void init() {
            itemList = new ArrayList();
            GUI gui1 = new GUI();
            getContentPane().add(gui1, "Center");
          }
    
        }
    
        public ArrayList getList() {
    
            // dummy return value of an empty list,
            // just to get the program to compile initially
            return itemList;
        }
    
        public ArrayList addToList(String s) {
            itemList.add(s);
            return itemList;
    
        }
    
        public ArrayList getSortedList() {
    
            // dummy return value of an empty list,
            // just to get the program to compile initially
            Collections.sort(itemList);
            return itemList;
        }
    
        public ArrayList performReverse() {
    
            // dummy return value of an empty list,
            // just to get the program to compile initially
            Collections.reverse(itemList);
            return itemList;
        }
    
        public ArrayList performDeletion(int i) {
    
            // dummy return value of an empty list,
            // just to get the program to compile initially
            if(i < itemList.size())
                itemList.remove(i);
                        return itemList;
        }
    
        public ArrayList performSwap(int i) {
    
            // dummy return value of an empty list,
            // just to get the program to compile initially
            if(i < itemList.size() && itemList.size() >=2)
            {
                String s = (String)itemList.remove(i);
                if(i < itemList.size())
                    itemList.add(i + 1, s);
                else
                    itemList.add(itemList.size() - 1, s);
            }
            return itemList;
       }
    
        private GUI gui;
        private ArrayList itemList;
        public static void main(String args[])
    {
    
        }
    }

Similar Threads

  1. Java book
    By Lou in forum Java
    Replies: 9
    Last Post: 09-19-2007, 05:58 AM
  2. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 06:46 AM
  3. NETBEANS IDE VERSION 3.2 RELEASED
    By George Dvorak in forum Open Source
    Replies: 0
    Last Post: 05-06-2001, 08:01 AM
  4. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center