Results 1 to 4 of 4
  1. #1
    Shien is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Reading from file to array error

    Java Code:
    BufferedReader br = new BufferedReader(new FileReader(filename));                 
                        for(int t = 1; t < 50;t++)
                        {
                            array[t] = br.readLine();
                        }
                        for(int i = 0; i < array.length; i++)
                        {
                            System.out.println(array[i]);
                        }
    I get nullPointerException. How to fix it?

  2. #2
    Shien is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: Reading from file to array error

    I manage to fix the problem, but now I get another problem.
    Java Code:
    BufferedReader br = new BufferedReader(new FileReader(filename));                 
                        for(int t = 0; t < 20;t++)
                        {
                                array[t] = br.readLine();
                        }
                        for(int i = 0; i < array.length; i++)
                        {
                            if(array[i] != null)
                            {
                                System.out.println(array[i]);
                            }
                        }
                        String[][]tempArray = new String[array.length][];
                        for(int t = 0; t < array.length;t++)
                        {
                            tempArray[t] = array[t].split(";");
                        }
                        String[] iArray = new String[tempArray.length];
                        String[] tArray = new String[tempArray.length];
                        for(int i = 0; i < tempArray.length; i++)
                        {
                            iArray[i] = tempArray[i][0];
                            tArray[i] = tempArray[i][1];   
                        }
    in the system output it says that the problem starts there:
    tempArray[t] = array[t].split(";");

  3. #3
    CHLim is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default Re: Reading from file to array error

    I'm guessing that you didn't initialize the tempArray properly.

  4. #4
    joeyvitoro is offline Member
    Join Date
    Oct 2011
    Posts
    90
    Rep Power
    0

    Default Re: Reading from file to array error

    Your problem is here:
    Java Code:
    String[][]tempArray = new String[array.length][];
    The array needs a column size.

Similar Threads

  1. Reading a .txt file into an array
    By nifa98 in forum New To Java
    Replies: 4
    Last Post: 11-28-2011, 08:04 AM
  2. Reading a file into an array?
    By heycoa in forum New To Java
    Replies: 4
    Last Post: 07-07-2011, 05:22 AM
  3. Help with reading file into array
    By xkillswitchx14 in forum New To Java
    Replies: 2
    Last Post: 04-28-2011, 11:24 PM
  4. Help with reading from file into an array
    By Trad in forum New To Java
    Replies: 3
    Last Post: 10-22-2010, 01:16 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
  •