Results 1 to 6 of 6
  1. #1
    leapinlizard is offline Member
    Join Date
    Apr 2009
    Posts
    19
    Rep Power
    0

    Default Public static method error

    Hi, I'm really confused when i make print report method i'm getting errors if I take both methods out then it works fine here's my code:
    like if I take out:
    public void buildInstaces() and public void printReport() and let it run regular code it works fine no errors at all .. please help me solve this problem thanks.
    Java Code:
    public class BookTest
    {
    
            static Book bookArray[] = new Book[4]; 
    
    		
    	public static void main(String args[])
    
    	{
                   //Book bookArray[] = new Book[4]; 
    		// i will call all the methods here
    
                    
    
    	}
    
    	public static void buildInstances()
    	{
    
    	 	String dataArray [][] = {{"Where's my car", "Aston Kutcher","777","ORiely","Dallas","5.95","Fiction","123","456"},
    					 {"Earthquakes","ChuckBerry","435","LABooks","LA","75.00","NonFiction"},
    					 {"Doom","The Rock","918","Sans Publishing","LA","12.50","Fiction","1233","2323"}, 
    					 {"Universal Studios","Walt","987","Dell","Houston","29.90","NonFiction"}};
    	 
    	}//build instances
    
    
    	public void printReport()
    	{ //print report
    
                   for (int i=0; i<bookArray.length; i++)
                    {
                    	
     			if (dataArray[i][6].equals("Fiction"))
    
                       	    bookArray[i]=new Fiction (dataArray[i][0],dataArray[i][1], Integer.parseInt(dataArray[i][2]), new Publisher(dataArray[i][3],dataArray[i][4]), Double.parseDouble(dataArray[i][5]),i, new Background(Integer.parseInt(dataArray[i][7]), dataArray[i][8]));
     
    
                             
    			if (dataArray[i][6].equals("NonFiction"))
                                bookArray[i]= new NonFiction(dataArray[i][0],dataArray[i][1], Integer.parseInt(dataArray[i][2]), new Publisher(dataArray[i][3],dataArray[i][4]), Double.parseDouble(dataArray[i][5]),"History");
    			
                                                           
    	           		
    		}// end of FOR Loop
    
    
                
             	
                    for (int j=0; j<4;j++)
                        {
                         bookArray[j].calculateTotalCharge(Double.parseDouble(dataArray[j][5])+2*3);                
                 	    System.out.println();
    		    System.out.println();
    
    		    
    			System.out.printf(bookArray[j].toString());
    			
                        } //end of for with j  
    
     		}///print report 	               
    
    
    
    
       //  } //end of main
    
    
    } //end class BookTest

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default

    Please post the errors you're getting. Also, the following isn't doing anything:
    Java Code:
    public static void main(String args[])
    
    	{
                   //Book bookArray[] = new Book[4]; 
    		// i will call all the methods here
    
                    
    
    	}
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    leapinlizard is offline Member
    Join Date
    Apr 2009
    Posts
    19
    Rep Power
    0

    Default

    ok the error is : cannot find symbol variable dataArray

    also i know the main method is not going to do anything but i'm just trying to run as it is @ this moment

    i can add in main method like this:
    buildInstances();
    printReport();

  4. #4
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    In your buildInstances() method you create String dataArray [][] = but it is only a local variable for that method... So when you call it in your printReport() method, it is no where to be found...

    You need to make it static like your bookArray[]...
    Who Cares... As Long As It Works...

  5. #5
    leapinlizard is offline Member
    Join Date
    Apr 2009
    Posts
    19
    Rep Power
    0

    Default

    ok when i type like this:

    static String dataArray[][] = ......

    then i compile it says : illegal start of expression

  6. #6
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    You need to do it in the same place as well... Like so:


    Java Code:
    static Book bookArray[] = new Book[4]; 
    static String dataArray [][];
    		
    	public static void main(String args[])
    
    	{
                   //Book bookArray[] = new Book[4]; 
    		// i will call all the methods here
    
                    
    
    	}
    
    	public static void buildInstances()
    	{
    
    	       dataArray [][] = {{"Where's my car", "Aston Kutcher","777","ORiely","Dallas","5.95","Fiction","123","456"},
    					 {"Earthquakes","ChuckBerry","435","LABooks","LA","75.00","NonFiction"},
    					 {"Doom","The Rock","918","Sans Publishing","LA","12.50","Fiction","1233","2323"}, 
    					 {"Universal Studios","Walt","987","Dell","Houston","29.90","NonFiction"}};
    	 
    	}//build instances

    .
    Who Cares... As Long As It Works...

Similar Threads

  1. Replies: 3
    Last Post: 04-11-2009, 09:14 PM
  2. Replies: 1
    Last Post: 02-10-2009, 10:03 AM
  3. Replies: 9
    Last Post: 11-22-2008, 11:03 PM
  4. Non-Static method in static context error
    By wizmang in forum New To Java
    Replies: 4
    Last Post: 04-24-2008, 08:51 AM
  5. Replies: 1
    Last Post: 08-07-2007, 05:05 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
  •