Results 1 to 3 of 3
  1. #1
    prizzly is offline Member
    Join Date
    Dec 2010
    Posts
    5
    Rep Power
    0

    Exclamation java.lang.NumberFormatException: null

    Hi,

    How can I compare null value in string array. I want escape null elements.

    private static void arrange(String[][] arr1)
    {
    for (int i=0;i<=count;i++)
    {
    for(int j=0;j<arr1.length;j++)
    {
    if (i==0)
    {
    int n=Integer.parseInt(arr1[i][j]);
    System.out.println("...."+n);
    }

    if (j==1)
    {
    if ((arr1[i][j]).equals(null)) // I had used != , == nothing worked
    { System.out.println("----------");
    continue;
    }
    else
    { System.out.println("--**********----");
    int m=Integer.parseInt(arr1[i][1]);
    System.out.println(">"+m);

    }
    }
    System.out.print(arr1[i][j]);
    }
    }

    }



    My Input array is as follows.

    5 null null null null
    Stephen 1 null null null
    Tommaso null null null null
    Tommaso 1 null null null
    Galileo null null null null
    Isaac 1 null null null
    Tommaso null null null null
    Galileo 1 null null null
    Tommaso null null null null
    George 2 null null null
    Isaac null null null null
    Stephen null null null null

  2. #2
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    are you sure its null? Where does the array come from ? user input ? Have you checked for "" yet?

  3. #3
    prizzly is offline Member
    Join Date
    Dec 2010
    Posts
    5
    Rep Power
    0

    Unhappy

    I am reading a file and putting the info in a array.
    file:
    5
    Stephen 1
    Tommaso
    Tommaso 1
    Galileo
    Isaac 1
    Tommaso
    Galileo 1
    Tommaso
    George 2
    Isaac
    Stephen

    array after reading file is as follows:

    5 null null null null
    Stephen 1 null null null
    Tommaso null null null null
    Tommaso 1 null null null
    Galileo null null null null
    Isaac 1 null null null
    Tommaso null null null null
    Galileo 1 null null null
    Tommaso null null null null
    George 2 null null null
    Isaac null null null null
    Stephen null null null null

    now I want to create an array as

    Stephen 1 0 Tommaso
    Tommaso 1 0 Galileo
    Issac 1 0 Tommaso
    Galileo 1 0 Tommaso
    George 2 0 Issac Stephen

    This is my full code...


    import java.lang.*;
    import java.io.*;

    public class Test
    {

    static int count;
    static String[][] arr=new String[12][5];

    public static void main(String[] args)
    {
    String[] lines = new String[0];
    String path = "Liar.txt";
    BufferedReader br = null;

    try {
    File file = new File(path);
    br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
    String line;

    while( (line = br.readLine()) != null )
    {
    print(line);
    }
    br.close();

    } catch(IOException e)
    {
    System.out.println("read error: " + e.getMessage());
    }

    for(int x=0;x<12;x++)
    {
    for(int y=0;y<5;y++)
    {
    System.out.print(arr[x][y]+" ");
    }
    System.out.print("\n");
    }
    arrange(arr);
    }


    private static void print(String data1)
    {

    String data=data1.replaceAll("\\b\\s{2,}\\b", " "); // replace multiple spaces by a single space between words
    String[] words = data.split("\\s"); //words is an array of splitted words in a line(1 space considered as 1 word)

    for(int j = 0; j < words.length; j++) //word.length gives no. of words in a line.
    {
    arr[count][j]=words[j];
    }
    count++;
    }

    private static void arrange(String[][] arr1)
    {
    for (int i=0;i<=count;i++)
    {
    for(int j=0;j<arr1.length;j++)
    {
    if (i==0)
    {
    int n=Integer.parseInt(arr1[i][j]);
    System.out.println("...."+n);
    }

    if (j==1)
    {
    if ((arr1[i][j]).equals(null))
    { System.out.println("----------");
    continue;
    }
    else
    { System.out.println("--**********----");
    int m=Integer.parseInt(arr1[i][1]);
    System.out.println(">"+m);
    }
    }
    System.out.print(arr1[i][j]);
    }
    }

    }
    }

Similar Threads

  1. Replies: 5
    Last Post: 04-12-2010, 04:39 PM
  2. Replies: 3
    Last Post: 06-07-2009, 01:14 AM
  3. Exception java.lang.NumberFormatException
    By vasavi.singh in forum New To Java
    Replies: 3
    Last Post: 02-24-2009, 07:27 AM
  4. Replies: 2
    Last Post: 08-07-2007, 04:50 PM
  5. java.lang.NumberFormatException: null
    By Eric in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-05-2007, 06:31 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •