473,699 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

nullpointerexce ption

oll3i
679 Contributor
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.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
Jul 8 '07 #1
3 1666
JosAH
11,448 Recognized Expert MVP
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
Jul 8 '07 #2
oll3i
679 Contributor
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);

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 Recognized Expert MVP
System.out.prin tln() 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
8572
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 code below: RequestDispatcher dispatcher = myConfig.getServletContext().getRequestDispatcher(view); dispatcher.forward(request, response); The funny thing is that it will do most of the database work it's supposed to, but then gives me the...
4
4070
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
4410
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 show up via tomcat. I'm running on Fedora Core 2, tomcat-4.1.27-13. I haven't noticed any difference if I start apache httpd-2.0.50-2.1 or not. Here are the errors: MsgAjp - -BAD packet signature 18245
2
3078
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 sun.awt.RepaintArea.paint(RepaintArea.java:177) at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260) at java.awt.Component.dispatchEventImpl(Component.java:3678) at java.awt.Container.dispatchEventImpl(Container.java:1627)
13
1966
oll3i
by: oll3i | last post by:
private List<Klient> klienci; m_add_client.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try{
1
2474
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 TextField t1, t2, t3;
2
2275
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 already exist) in my application using the Design Editor. I go about this by right-clicking on the JButton in the design editor, navigating to Events -> Action -> actionPerformed. The auto-generated code appears for a brief moment before it...
1
3189
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 already exist) in my application using the Design Editor. I go about this by right-clicking on the JButton in the design editor, navigating to Events -> Action -> actionPerformed. The auto-generated code appears for a brief moment before it...
1
17543
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 before, lending proof to Einstein's statement: “Only two things are infinite, the universe and human stupidity ...”. Main Cause Dereferencing null. This is by far the more common cause of getting the exception. Reference types in both...
3
3334
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 { ArrayList<String> dictionary; ArrayList<String> encryptedText;
0
9173
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9033
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6533
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5872
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.