473,326 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

nullpointerexception

oll3i
679 512MB
Expand|Select|Wrap|Line Numbers
  1. double[] dystanse = null;
  2.         Integer[] czyNajblizszySasiad = null;
  3.         Integer[] najblizszySasiad=null;
  4.  
  5.  
  6.  
  7.         System.out.println("Przed 1 petla for");
  8.         for(int j=0;j<=10;j++){
  9.         System.out.println("W 1 petli for");
  10.          if(j!=aktualnyWiersz){
  11.          System.out.println("Przed 2 petla for");        
  12.            for(int i=0;i<cols-1;i++){
  13.            System.out.println(i+". W 2 petli for Dokladamy dystans do tablicy");
  14.            czyNajblizszySasiad[i]=klasyfikatorNN.dane_treningowe[j][i];
  15.            System.out.println("klasyfikatorNN.dane_treningowe[j][i]"+klasyfikatorNN.dane_treningowe[j][i]);
  16.            dystanse[j]=klasyfikatorNN.liczDystans(czyNajblizszySasiad);
  17.             }
  18.          }else{
  19.               System.out.println("j rowne aktualnemu wierszowi");
  20.               dystanse[j]=0;
  21.               }
  22.         }
  23.  
i did lots of system.out.printlns 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.NullPointerException
at Test$2.actionPerformed(Test.java)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)Przed 1 petla for
W 1 petli for
j rowne aktualnemu wierszowi

at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Test$2.actionPerformed(Test.java)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Przed 1 petla for
W 1 petli for
j rowne aktualnemu wierszowi

thank YOU
Jul 8 '07 #1
3 1641
JosAH
11,448 Expert 8TB
From what I can see from your code: array 'czyNajblizszySasiad' 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
Jul 8 '07 #2
oll3i
679 512MB
i found that one have another one

dystans+=Math.sqrt(Math.pow((double)wiersz_analizo wany[i],(double)2)-Math.pow((double)czyNajblizszySasiad[i],(double)2)); returns 0.0 or NaN
when wiersz_analizowany[i] and czyNajblizszySasiad[i] are equal to 0 ,1 ,2 or 3
what NaN means ?


and

najblizszySasiad=klasyfikatorNN.znajdzNajblizszego Sasiada(dystanse);

Expand|Select|Wrap|Line Numbers
  1. public Integer[] znajdzNajblizszegoSasiada(double[] dystanse){
  2.     double dystansTemp=0;
  3.     int MinDystansIndex=0;
  4.     for(int i=0;i<liczbaWierszy;i++){
  5.         if(dystanse[i]==0) continue;
  6.         if(dystansTemp>dystanse[i]){
  7.            dystansTemp=dystanse[i];
  8.            MinDystansIndex=i;
  9.  
  10.         }
  11.     }
  12.     for(int i=0;i<liczbaColumn;i++)
  13.     najblizszy_sasiad[i]=dane_treningowe[MinDystansIndex][i];
  14.     return najblizszy_sasiad;
  15. }
  16.  
returns another nullpointer exception


thank YOU
Jul 8 '07 #3
JosAH
11,448 Expert 8TB
System.out.println() is your poor men's debugging friend; stick code like this:

Expand|Select|Wrap|Line Numbers
  1. if (myArray == null)
  2.    System.out.println("myArray is null");
  3.  
.... everywhere you suspect something.

Gotta run now,

kind regards,

Jos
Jul 8 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: K S Aldebaraan | last post by:
I'm trying to submit a form with an action of a servlet, and a view equal to the same jsp page. I'm not sure what I'm doing wrong, but keep getting a NullPointerException on the second line of...
4
by: gabryh | last post by:
Hi, The following code throws me NullPointerException. ..... public static boolean isEmpty(String value) { return ((value == null) || (value.trim().equals(""))); }
0
by: Old-timer | last post by:
Not sure where else to post this. I'm sure I'm doing something wrong, but I wouldn't think a simple app would give me so much trouble. I've got a small test java class that I'm trying to have...
2
by: Smith | last post by:
The program compiled successfully, but it gives the following error on runtime.... java.lang.NullPointerException at FrogManiaApp.paint(FrogManiaApp.java:102) at...
13
oll3i
by: oll3i | last post by:
private List<Klient> klienci; m_add_client.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ...
1
by: ketand1 | last post by:
import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import java.sql.*; import java.lang.*; class DbAwt extends Frame implements ActionListener { private...
2
by: sokeefe | last post by:
I am trying to edit the GUI of a project in Netbeans. In particular, I am trying to add new JButtons. I get a NullPointerException when I try to add an Event to any given JButton (even ones that...
1
by: sokeefe | last post by:
I am trying to edit the GUI of a project in Netbeans. In particular, I am trying to add new JButtons. I get a NullPointerException when I try to add an Event to any given JButton (even ones that...
1
by: r035198x | last post by:
This exception occurs often enough in practice to warrant its own article. It is a very silly exception to get because it's one of the easiest exceptions to avoid in programming. Yet we've all got it...
3
by: chris123456789 | last post by:
Hi, when I run my code I get a NullPointerException:null. Here is the part of the code where the error occurs: import java.util.*; import java.io.*; public class Decrypt { ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.