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

    Default Solve the Error:null issue

    Hi everyone I am trying to write a code which creates a 3 dimensional array using the lines from a textfile.
    the text file will have 25 lines. all lines will have different number of stops string. in this code the first line of the text file will have:
    stop1 stop2 stop3 stop4

    my code below should return stop1 but instead its returning "Error:null"
    please help. i want to know what im doing wrong. :

    import java.util.*;
    import java.io.*;
    public class Reading
    {
    public static void main(String[] args) throws IOException
    {
    int a,b,c;
    String read;
    String[] Astop;
    String[][][] AllStops;
    AllStops=new String[5][5][];
    try
    {
    FileInputStream fstream = new FileInputStream("textfile.txt");
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    for(a=0;a<5;a++)
    {
    for(b=0;b<5;b++)
    {
    read=br.readLine();
    Astop=read.split(" ");

    if(read==null)
    {
    AllStops[a][b]= new String[1];
    AllStops[a][b][0]=" ";
    }
    else
    {
    AllStops[a][b]= new String[Astop.length];
    for(c=0;c<Astop.length;c++)
    {
    AllStops[a][b][c]=Astop[c];
    }
    }
    }

    }
    System.out.print(AllStops[0][0][0]);
    in.close();
    }
    catch (Exception e)
    {//Catch exception if any
    System.err.println("Error: " + e.getMessage());
    }
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default

    Java Code:
    catch (Exception e)
    {//Catch exception if any
    System.err.println("Error: " + e.getMessage());
    }
    Insetad of doing this do e.printStackTrace(), so you get all the data on the exception. That way you'll find out which line is causing the problem, which should tell you which object is null.

    Also use code tags when posting code (quote my post to see them in action).

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

    Default

    Thank you so much!! Life saver :D
    Ill be sure to use code tags next time. Hopefully, I wont need to post another question anytime soon :)

Similar Threads

  1. Null Pointer Exception Issue
    By D-Rock in forum New To Java
    Replies: 3
    Last Post: 11-28-2010, 11:38 PM
  2. plz solve this error
    By silversurfer2in in forum AWT / Swing
    Replies: 14
    Last Post: 06-15-2010, 03:30 PM
  3. How to solve this issue.
    By yaso in forum Eclipse
    Replies: 1
    Last Post: 11-07-2009, 07:28 AM
  4. help required to solve jasper report memory issue
    By kiranrajan in forum Advanced Java
    Replies: 0
    Last Post: 11-04-2009, 09:25 AM
  5. Help mi solve my error
    By Deon in forum New To Java
    Replies: 3
    Last Post: 01-11-2008, 05:26 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
  •