Results 1 to 5 of 5
  1. #1
    csuever is offline Member
    Join Date
    Mar 2011
    Posts
    13
    Rep Power
    0

    Default text into array...nullpointerexception

    My program compiles, and i've used this method before but when I go to run it, I get the java.lang.nullpointerexception and its showing that where my pin[i] first used under the computerScoresheet is where it is first happening. If someone could please explain why it is doing this and what I need to do in order to get the data into my array it would be much appreciated. Thank you
    Attached Files Attached Files

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Anyway you can post the code directly? I and many others would rather not download or follow links.

  3. #3
    csuever is offline Member
    Join Date
    Mar 2011
    Posts
    13
    Rep Power
    0

    Default

    private Bowler(){
    }
    public Bowler(String name, String game, String f){
    this.name = name;
    this.game = game;
    String filename = f;
    pins = new int[23];
    try{
    Scanner s = new Scanner(new FileReader("bowl.txt"));

    int i = 0;
    while(s.hasNextLine()){
    pins[i] = s.nextInt();
    i++;
    }
    s.close();
    System.out.println(pins[i]);
    }catch(Exception e){e.printStackTrace();}
    }

    private void computeScoresheet(){
    int i = 0;
    for(int frame = 1; frame < 10; frame++) // frames 1-9
    {
    if(pins[i] == 10)
    {
    scoresheet += "X";
    i++; // observed one element
    }
    else if(pins[i] + pins[i+1] == 10)
    {
    scoresheet += pins[i] + "/";
    i+= 2; //observed two elements
    }
    else if(pins[i] != 0)
    {
    scoresheet += pins[i];
    i++;

    }
    else{
    scoresheet += "-";
    }

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default

    Please post all your code. When you do place [ code ] before and [ /code ] (without the spaces) after your code. Also post the EXACT error message you get and indicate on which line it occurs.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default

    Ahhh!

    I see you have created another thread. Don't do this. Keep all your questions in the same thread to avoid situations like this.

Similar Threads

  1. Replies: 8
    Last Post: 03-31-2011, 06:09 AM
  2. NullPointerException in FileInputStream text file
    By cheskers11 in forum Eclipse
    Replies: 1
    Last Post: 11-19-2009, 01:38 PM
  3. Reading text file into an array
    By Mahesh_ps in forum New To Java
    Replies: 1
    Last Post: 10-09-2009, 03:04 PM
  4. GUI help - Text Box Defaults to Array Value
    By ejs7597 in forum New To Java
    Replies: 8
    Last Post: 03-31-2009, 05:48 AM
  5. Export an array to a text file
    By carderne in forum New To Java
    Replies: 32
    Last Post: 10-02-2008, 03:52 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
  •