Results 1 to 7 of 7
  1. #1
    coopc is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default dfgdfgvb

    dfgdfgddsdfgsdvcxvbcvbcxvb
    Last edited by coopc; 04-27-2011 at 10:26 PM.

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    Java Code:
    BusData data=new BusData();
    in Search.java is probably empty hence nullpointer with data.JourneyArray[position]

    I think you need to add a method in Main.java to retrieve the field 'data' from other classes.

    Main.java
    Java Code:
    ...
    public static BusData getData() {
        return data;
    }
    Search.java
    Java Code:
    //BusData data=new BusData();
    BusData data = new Main().getData();

  3. #3
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default

    Which line is line 57?

  4. #4
    coopc is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default

    ozzyman i tried what you said but it didnt work :(

    kjkrum heres line
    Java Code:
    System.out.println(search.showTime(0,1));

  5. #5
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    Quote Originally Posted by coopc View Post
    ozzyman i tried what you said but it didnt work :(

    kjkrum heres line
    Java Code:
    System.out.println(search.showTime(0,1));
    I didn't give you the full solution...

    you need to create a constructor in Main.java and run your Main.main() method before you use getData() otherwise the field 'data' still won't have any values in it

  6. #6
    coopc is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default

    So do I add this to the Main.java:
    Java Code:
    	BusData datas;
    	public Main()
    	{
    		datas=null;
    	}
    	public void setData(BusData  datas)
    	{
    		this.datas=datas;
    	}
    	public BusData  getData() 
    	{
    		return datas;
    	}
    and then add this in Search.java:
    Java Code:
    BusData data = new Main().getData();
    I tried that and i still have the same error

  7. #7
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    datas = null? no, you're supposed to run your whole method so that you fill up data with actual values.

    Java Code:
    public class MyClass {
      private BusData data;
    
      MyClass() {
          main();
      }
    
      public static void main() {
          data = new BusData();
          for(int i=0; i<someObject.length; i++) {
               data += someObject[i].value();
          }
      }
    
      public BusData getData() {
        return data;
      }
    }

Similar Threads

  1. Replies: 3
    Last Post: 03-15-2011, 12:24 PM
  2. Replies: 2
    Last Post: 03-08-2011, 06:20 AM
  3. Searching and comparing Array elements
    By jmanswrd in forum New To Java
    Replies: 5
    Last Post: 02-15-2011, 06:06 AM
  4. Sorting/Searching Objects with multiple types.
    By gcampton in forum New To Java
    Replies: 20
    Last Post: 10-21-2009, 11:58 PM
  5. Searching In a String Array - Problem
    By DillMan in forum New To Java
    Replies: 4
    Last Post: 12-07-2008, 09:12 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
  •