Results 1 to 3 of 3
Thread: Solve the Error:null issue
- 04-12-2011, 04:48 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 18
- Rep Power
- 0
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());
}
}
}
- 04-12-2011, 05:19 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.Java Code:catch (Exception e) {//Catch exception if any System.err.println("Error: " + e.getMessage()); }
Also use code tags when posting code (quote my post to see them in action).
- 04-12-2011, 06:18 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 18
- Rep Power
- 0
Similar Threads
-
Null Pointer Exception Issue
By D-Rock in forum New To JavaReplies: 3Last Post: 11-28-2010, 11:38 PM -
plz solve this error
By silversurfer2in in forum AWT / SwingReplies: 14Last Post: 06-15-2010, 03:30 PM -
How to solve this issue.
By yaso in forum EclipseReplies: 1Last Post: 11-07-2009, 07:28 AM -
help required to solve jasper report memory issue
By kiranrajan in forum Advanced JavaReplies: 0Last Post: 11-04-2009, 09:25 AM -
Help mi solve my error
By Deon in forum New To JavaReplies: 3Last Post: 01-11-2008, 05:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks