nullpointerexception

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

    #1

    nullpointerexception

    [code=java]
    double[] dystanse = null;
    Integer[] czyNajblizszySa siad = null;
    Integer[] najblizszySasia d=null;



    System.out.prin tln("Przed 1 petla for");
    for(int j=0;j<=10;j++){
    System.out.prin tln("W 1 petli for");
    if(j!=aktualnyW iersz){
    System.out.prin tln("Przed 2 petla for");
    for(int i=0;i<cols-1;i++){
    System.out.prin tln(i+". W 2 petli for Dokladamy dystans do tablicy");
    czyNajblizszySa siad[i]=klasyfikatorNN .dane_treningow e[j][i];
    System.out.prin tln("klasyfikat orNN.dane_treni ngowe[j][i]"+klasyfikatorN N.dane_treningo we[j][i]);
    dystanse[j]=klasyfikatorNN .liczDystans(cz yNajblizszySasi ad);
    }
    }else{
    System.out.prin tln("j rowne aktualnemu wierszowi");
    dystanse[j]=0;
    }
    }
    [/code]

    i did lots of system.out.prin tlns but i still can not locate the exception
    seems like it doesnt go through the 1st for loop goes only once and throws exception




    Exception in thread "AWT-EventQueue-0" java.lang.NullP ointerException
    at Test$2.actionPe rformed(Test.ja va)
    at javax.swing.Abs tractButton.fir eActionPerforme d(Unknown Source)
    at javax.swing.Abs tractButton$Han dler.actionPerf ormed(Unknown Source)
    at javax.swing.Def aultButtonModel .fireActionPerf ormed(Unknown Source)
    at javax.swing.Def aultButtonModel .setPressed(Unk nown Source)
    at javax.swing.pla f.basic.BasicBu ttonListener.mo useReleased(Unk nown Source)
    at java.awt.Compon ent.processMous eEvent(Unknown Source)
    at javax.swing.JCo mponent.process MouseEvent(Unkn own Source)Przed 1 petla for
    W 1 petli for
    j rowne aktualnemu wierszowi

    at java.awt.Compon ent.processEven t(Unknown Source)
    at java.awt.Contai ner.processEven t(Unknown Source)
    at java.awt.Compon ent.dispatchEve ntImpl(Unknown Source)
    at java.awt.Contai ner.dispatchEve ntImpl(Unknown Source)
    at java.awt.Compon ent.dispatchEve nt(Unknown Source)
    at java.awt.Lightw eightDispatcher .retargetMouseE vent(Unknown Source)
    at java.awt.Lightw eightDispatcher .processMouseEv ent(Unknown Source)
    at java.awt.Lightw eightDispatcher .dispatchEvent( Unknown Source)
    at java.awt.Contai ner.dispatchEve ntImpl(Unknown Source)
    at java.awt.Window .dispatchEventI mpl(Unknown Source)
    at java.awt.Compon ent.dispatchEve nt(Unknown Source)
    at java.awt.EventQ ueue.dispatchEv ent(Unknown Source)
    at java.awt.EventD ispatchThread.p umpOneEventForF ilters(Unknown Source)
    at java.awt.EventD ispatchThread.p umpEventsForFil ter(Unknown Source)
    at java.awt.EventD ispatchThread.p umpEventsForHie rarchy(Unknown Source)
    at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
    at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
    at java.awt.EventD ispatchThread.r un(Unknown Source)
    Exception in thread "AWT-EventQueue-0" java.lang.NullP ointerException
    at Test$2.actionPe rformed(Test.ja va)
    at javax.swing.Abs tractButton.fir eActionPerforme d(Unknown Source)
    at javax.swing.Abs tractButton$Han dler.actionPerf ormed(Unknown Source)
    at javax.swing.Def aultButtonModel .fireActionPerf ormed(Unknown Source)
    at javax.swing.Def aultButtonModel .setPressed(Unk nown Source)
    at javax.swing.pla f.basic.BasicBu ttonListener.mo useReleased(Unk nown Source)
    at java.awt.Compon ent.processMous eEvent(Unknown Source)
    at javax.swing.JCo mponent.process MouseEvent(Unkn own Source)
    at java.awt.Compon ent.processEven t(Unknown Source)
    at java.awt.Contai ner.processEven t(Unknown Source)
    at java.awt.Compon ent.dispatchEve ntImpl(Unknown Source)
    at java.awt.Contai ner.dispatchEve ntImpl(Unknown Source)
    at java.awt.Compon ent.dispatchEve nt(Unknown Source)
    at java.awt.Lightw eightDispatcher .retargetMouseE vent(Unknown Source)
    at java.awt.Lightw eightDispatcher .processMouseEv ent(Unknown Source)
    at java.awt.Lightw eightDispatcher .dispatchEvent( Unknown Source)
    at java.awt.Contai ner.dispatchEve ntImpl(Unknown Source)
    at java.awt.Window .dispatchEventI mpl(Unknown Source)
    at java.awt.Compon ent.dispatchEve nt(Unknown Source)
    at java.awt.EventQ ueue.dispatchEv ent(Unknown Source)
    at java.awt.EventD ispatchThread.p umpOneEventForF ilters(Unknown Source)
    at java.awt.EventD ispatchThread.p umpEventsForFil ter(Unknown Source)
    at java.awt.EventD ispatchThread.p umpEventsForHie rarchy(Unknown Source)
    at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
    at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
    at java.awt.EventD ispatchThread.r un(Unknown Source)
    Przed 1 petla for
    W 1 petli for
    j rowne aktualnemu wierszowi

    thank YOU
    Last edited by oll3i; Jul 8 '07, 03:00 PM. Reason: typo
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    From what I can see from your code: array 'czyNajblizszyS asiad' is null when
    you dereference it from within the body of your for loop in line 14 according to
    the code you posted.

    kind regards,

    Jos

    Comment

    • oll3i
      Contributor
      • Mar 2007
      • 679

      #3
      i found that one have another one

      dystans+=Math.s qrt(Math.pow((d ouble)wiersz_an alizowany[i],(double)2)-Math.pow((doubl e)czyNajblizszy Sasiad[i],(double)2)); returns 0.0 or NaN
      when wiersz_analizow any[i] and czyNajblizszySa siad[i] are equal to 0 ,1 ,2 or 3
      what NaN means ?


      and

      najblizszySasia d=klasyfikatorN N.znajdzNajbliz szegoSasiada(dy stanse);

      [code=Java]
      public Integer[] znajdzNajblizsz egoSasiada(doub le[] dystanse){
      double dystansTemp=0;
      int MinDystansIndex =0;
      for(int i=0;i<liczbaWie rszy;i++){
      if(dystanse[i]==0) continue;
      if(dystansTemp> dystanse[i]){
      dystansTemp=dys tanse[i];
      MinDystansIndex =i;

      }
      }
      for(int i=0;i<liczbaCol umn;i++)
      najblizszy_sasi ad[i]=dane_treningow e[MinDystansIndex][i];
      return najblizszy_sasi ad;
      }
      [/code] returns another nullpointer exception


      thank YOU

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        System.out.prin tln() is your poor men's debugging friend; stick code like this:

        [code=java]
        if (myArray == null)
        System.out.prin tln("myArray is null");
        [/code]

        .... everywhere you suspect something.

        Gotta run now,

        kind regards,

        Jos

        Comment

        Working...