nullpointer exception when assigning values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    #1

    nullpointer exception when assigning values

    [code=java]
    public void wczytajPlik(Str ing sciezka) throws FileNotFoundExc eption
    {
    wczytaneDane.se tText("");
    BufferedReader br = new BufferedReader( new FileReader(scie zka));
    String line = null;
    String[] rows_cols = null;
    try {
    line = br.readLine();
    rows_cols = line.split("\\s +");
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTra ce();
    }

    int rows=new Integer(rows_co ls[0]);
    int cols=new Integer(rows_co ls[1]);
    wczytaneDane.ap pend("Liczba wierszy:"+rows+ "\n");
    wczytaneDane.ap pend("Liczba kolumn:"+cols+" \n");
    klasyfikatorBay esa = new KlasyfikatorBay esa(cols-1,rows);
    System.out.prin tln("Kolumny i wiersze ustawione\n"+"l ine="+line);

    int lineNumber=0;

    String[] aktualnyWiersz= null;
    Integer valueRowColumn = null;
    try {
    while((line = br.readLine()) != null) {
    aktualnyWiersz = line.split("\\s +");


    for(int i=0;i<aktualnyW iersz.length-1;i++){

    ///int valueInt = new Integer(aktualn yWiersz[i]).intValue();
    try {
    valueRowColumn = new Integer(aktualn yWiersz[i]);
    } catch (NumberFormatEx ception ignored) {


    klasyfikatorBay esa.dane_trenin gowe[lineNumber][i]=valueRowColumn ;
    }


    }
    System.out.prin tln(lineNumber+ "line="+lin e);
    wczytaneDane.ap pend(lineNumber +")"+line+"\n") ;
    lineNumber++;
    }

    System.out.prin tln("Dane treningowe wczytane");
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTra ce();
    }

    }

    [/code]


    for(int i=0;i<liczbaCol umn;i++){
    System.out.prin tln("dane_treni ngowe[aktualny_wiersz][i]"+dane_treningo we[aktualny_wiersz][i]);
    wiersz_analizow any[i]=dane_treningow e[aktualny_wiersz][i];
    }

    when i do System.out.prin tln wiersz_analizow any[i] is null
    klasyfikatorBay esa.dane_trenin gowe[lineNumber][i]=valueRowColumn ; assigns null ? when i convert it to integer valueRowColumn = new Integer(aktualn yWiersz[i]); it returns NumberFormatExc eption


    thank YOU
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Here are some tips.
    1.) Define variables closet to where you're using them.
    2.) Ignoring exceptions is not the in-thing to do.
    3.) NumberFormatExc eption is what it says. You are trying to convert an inconvertible value. Print it to console and see what it is.

    Comment

    • oll3i
      Contributor
      • Mar 2007
      • 679

      #3
      i need to convert aktualnyWiersz[i] to Integer so i can assign value
      klasyfikatorBay esa.dane_trenin gowe[lineNumber][i]=valueRowColumn ;
      which is public Integer[][] dane_treningowe ;

      how do i conver String to Integer?

      Comment

      • oll3i
        Contributor
        • Mar 2007
        • 679

        #4
        Integer valueRowColumn = Integer.valueOf (aktualnyWiersz[i]); throws number format exception

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by oll3i
          i need to convert aktualnyWiersz[i] to Integer so i can assign value
          klasyfikatorBay esa.dane_trenin gowe[lineNumber][i]=valueRowColumn ;
          which is public Integer[][] dane_treningowe ;

          how do i conver String to Integer?
          Use Integer.parseIn t but you'll get an exception if the value being passed is not an integer.

          Comment

          Working...