Results 1 to 3 of 3
- 05-10-2012, 09:19 PM #1
Banned
- Join Date
- May 2012
- Posts
- 1
- Rep Power
- 0
Exception in thread "main" java.lang.NullPointerException
I am getting this exception in the code below for not initializing arraylist.. could someone please help me with this..:(
this problem is in g[i].v.add(vv);
class graph
{
public ArrayList<Integer[]> v=new ArrayList<Integer[]>();
public ArrayList<Integer[]> e=new ArrayList<Integer[]>();
}
public class main {
public static void main(String[] args) {
Integer vv[]=new Integer[2];
Integer ee[]=new Integer[3];
graph g[]=new graph[1000];
int i=-1;
String t="t";
String v="v";
String e="e";
FileInputStream fstream;
try {
fstream = new FileInputStream("graph1.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader b = new BufferedReader(new InputStreamReader(in));
String line;
try {
while ((line = b.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line);
if(t.equals(st.nextToken()))
{
i++;
}
line = b.readLine();
System.out.println(line);
StringTokenizer st1 = new StringTokenizer(line);
if(v.equals(st1.nextToken()))
{
vv[0]=Integer.parseInt(st1.nextToken());
vv[1]=Integer.parseInt(st1.nextToken());
g[i].v.add(vv);
}
line = b.readLine();
StringTokenizer st2 = new StringTokenizer(line);
if(e.equals(st2.nextToken()))
{
ee[0]=Integer.parseInt(st2.nextToken());
ee[1]=Integer.parseInt(st2.nextToken());
ee[2]=Integer.parseInt(st2.nextToken());
g[i].e.add(ee);
}
}
} catch (IOException ex) {
Logger.getLogger(main.class.getName()).log(Level.S EVERE, null, ex);
}
} catch (FileNotFoundException ex) {
Logger.getLogger(main.class.getName()).log(Level.S EVERE, null, ex);
}
}}
- 05-10-2012, 09:28 PM #2
Re: Exception in thread "main" java.lang.NullPointerException
What variable has a null value?
Please post the full text of the error message.
Some bad practices I see are:
using variable names that are only 1 character long
having more than one variable with the same name: e & v
You need to fix those.
Also use code tags: http://www.java-forums.org/misc.php?do=bbcode#codeLast edited by Norm; 05-10-2012 at 09:31 PM.
If you don't understand my response, don't ignore it, ask a question.
- 05-10-2012, 09:32 PM #3
Re: Exception in thread "main" java.lang.NullPointerException
Duplicate of Exception in thread "main" java.lang.NullPointerException
Closing the thread and banning the javagirl24 account.
db
THREAD CLOSEDWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Another Exception in thread "main" java.lang.NullPointerException problem
By wdh321 in forum New To JavaReplies: 6Last Post: 04-19-2012, 07:10 PM -
Got struck with this :- " Exception in thread "main" java.lang.NullPointerException"
By Vermont in forum New To JavaReplies: 5Last Post: 12-21-2011, 06:44 PM -
Exception in thread "main" java.lang.NullPointerException at LinkedList.main(Link
By kavitha_0821 in forum New To JavaReplies: 6Last Post: 07-16-2009, 03:30 PM -
Exception in thread "main" java.lang.NullPointerException at LinkedList.main(Link
By kavitha_0821 in forum New To JavaReplies: 1Last Post: 07-16-2009, 10:35 AM -
ArrayList: Exception in thread "main" java.lang.NullPointerException
By susan in forum New To JavaReplies: 1Last Post: 07-16-2007, 06:32 AM


LinkBack URL
About LinkBacks

Bookmarks