473,748 Members | 3,823 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 1668
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
8577
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
4076
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
4416
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
3083
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
1969
oll3i
by: oll3i | last post by:
private List<Klient> klienci; m_add_client.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try{
1
2504
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
2280
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
3193
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
17546
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
3341
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
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9541
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
9370
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
9321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8242
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
3312
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
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
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.