Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > Java

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 10-09-2009, 03:15 PM
p3t3r_uk p3t3r_uk is offline
Registered User
 
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!
Reply With Quote
  #2  
Old 10-13-2009, 05:36 AM
rohitsharma52 rohitsharma52 is offline
Registered User
 
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.
Reply With Quote
  #3  
Old 10-13-2009, 06:51 AM
p3t3r_uk p3t3r_uk is offline
Registered User
 
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.
Reply With Quote
  #4  
Old 10-13-2009, 07:32 AM
rohitsharma52 rohitsharma52 is offline
Registered User
 
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.
Reply With Quote
  #5  
Old 10-13-2009, 09:26 AM
p3t3r_uk p3t3r_uk is offline
Registered User
 
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[])
{

    }
}
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java book Lou Java 9 09-19-2007 06:58 AM
Java vs. .Net. A questionnaire Basil .NET 1 05-13-2005 07:46 AM
NETBEANS IDE VERSION 3.2 RELEASED George Dvorak Open Source 0 05-06-2001 09:01 AM
Re: VB vs. Visual Age for Java JJ Enterprise 1 07-06-2000 05:50 AM


All times are GMT -4. The time now is 11:23 PM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.