Results 1 to 4 of 4
  1. #1
    shhhhh is offline Member
    Join Date
    May 2012
    Posts
    1
    Rep Power
    0

    Unhappy Exception in thread "main" java.lang.NullPointerException

    what is the problem with the code.....:(



    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.StringTokenizer;
    import java.util.logging.Level;
    import java.util.logging.Logger;

    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);
    }

    }}


    Exception in thread "main" java.lang.NullPointerException

    at main.main(main.java:64)

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default Re: Exception in thread "main" java.lang.NullPointerException

    You tell us. What is the stack trace? Have you stepped through this wit ha debugger or at least added some print statements to figure out when the flow of the program differs from what you expect it to do?

    When posting code, please use the CODE tags.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Exception in thread "main" java.lang.NullPointerException

    Exception in thread "main" java.lang.NullPointerException
    at main.main(main.java:64)
    What variable on line 64 has a null value?
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Exception in thread "main" java.lang.NullPointerException

    shhhhh, don't double post and don't create more than one account. The other account you created has been banned and the double post has been locked.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 6
    Last Post: 04-19-2012, 08:10 PM
  2. Replies: 5
    Last Post: 12-21-2011, 07:44 PM
  3. Replies: 5
    Last Post: 10-11-2011, 01:16 AM
  4. Replies: 6
    Last Post: 07-16-2009, 04:30 PM
  5. Replies: 1
    Last Post: 07-16-2009, 11:35 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
  •