Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Classes problem

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Classes problem

    Hey

    I'm having a problem with classes and calling methods. I only know I have a problem at this point because Eclipse told me so. I've gone over it and over it and I just can't see what I did wrong here. Then again, I really don't know what I'm looking for. Here's the first class and call the the method in the second class. I'm trying to get an ArrayList<> I created passed into another method in a child class.
    package testP;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.io.*;
    import java.util.*;
     
    public class Test extends JFrame implements ActionListener {
    	private JButton enterQ, startTest, startOver, startTestOver, nextQuestion;
    	private JPanel buttonPanel; 
    	private JTextArea showQuestions, showAnswers, showCAnswers;
    	private JTextField enterQuestions, enterAnswers;
    	public ArrayList<String> questions[], corAnswers[], uAnswers[];
     
                 public Test() {
     
    	public void actionPerformed(ActionEvent e){
    		String command=e.getActionCommand();
                             if(command.equals("Enter Question")) {
    			String newQuestion=enterQuestions.getText();
    			String newAnswer=enterAnswers.getText();
    			addQ(newQuestion);
    			addA(newAnswer);
                             }
                 }
    }
    And here's the child class and relevent methods:
    package testP;
     
    import java.util.ArrayList;
     
    public class MakeTest extends Test {
    	ArrayList<String> q;
    	ArrayList<String> a;
    	public MakeTest() {
     
    	}
    		public ArrayList<String> addQ(String question) {
     
    			q.add(question);
    			return q;
    		}
     
    		public ArrayList<String> addA(String answer) {
     
    			a.add(answer);
    			return a;
    		}
    At this point, I'm not concerned about whether or not it actually does what it's supposed to do. I'm only concerned with why Eclipse says the call itself won't work. I'm doing something wrong, but I can't tell what. Thanks for any help given!
    Last edited by Skyton; March 3rd, 2011 at 12:54 PM.


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,099
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: Classes problem

    Eclipse says the call itself won't work
    And what does Eclipse say? Its usually very descriptive and leads to the problems, and since its not posted makes it difficult for us to pinpoint the issues. A brief look at the code: ArrayList's are objects, so you need to instantiate them (using new ArrayList() ). There also seem to be misuses of common functions (for example JFrame.add(String s) does not exist). Recommend you read the API's on the objects/functions you wish to use to familiarize yourself on how to use them

Similar Threads

  1. Problem in generation of custom classes at web service client
    By vinod.pandey in forum Member Introductions
    Replies: 0
    Last Post: January 10th, 2011, 06:12 AM
  2. cant run the program with 2 classes
    By clone_hiryu in forum Object Oriented Programming
    Replies: 5
    Last Post: November 17th, 2010, 11:28 PM
  3. [SOLVED] Abstract Classes Help
    By SweetyStacey in forum Object Oriented Programming
    Replies: 10
    Last Post: May 6th, 2010, 06:15 AM
  4. Problem to organize my code in classes
    By lumpy in forum Java Theory & Questions
    Replies: 2
    Last Post: February 21st, 2010, 11:13 AM
  5. [SOLVED] Java program using two classes
    By AZBOY2000 in forum Object Oriented Programming
    Replies: 7
    Last Post: April 21st, 2009, 06:55 AM