aspose file tools*
The moose likes Java in General and the fly likes Please help with NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Please help with NullPointerException" Watch "Please help with NullPointerException" New topic
Author

Please help with NullPointerException

Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
I cannot write the code in this forum, please open http://www.tawijakarta.blogspot.com to see my code.

Well, from the code you can see at my website, why do I get some below error messages?

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at PrgTesisServer.FrameBaru.<init>(ProgramTesisBaru.java:812)
at PrgTesisServer.ProgramTesisBaru$1.lanjut(ProgramTesisBaru.java:94)
at PrgTesisServer.ProgramTesisBaru$1.actionPerformed(ProgramTesisBaru.java:91)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
BUILD SUCCESSFUL (total time: 51 seconds)

1. How to call a class from a class?
2. Why do my frame with "Masukkan Hasil Analytic Hierarchical Process" title not show? What is wrong with the code?

Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2372
    
  28

Tawi

1) UseAMeaningfulSubjectLine. A lot of people are not going to read a thread that doesn't have a meaningful subject. I am going to edit your subject line for you.
2) The code posted on your blog is not readable . The blog software probably lost any formatting characters. You need to format your code. The forum software has a feature that allows you to post properly formatted code. Just wrap your code in code tags when you post it in the message

As far as your problem is concerned, it's impossible to help you without looking at what's on line 812 in ProgramTesisBaru.java. A reference variable used on that line is null
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1506
    
    5

Hi Tawi,

Welcome to CodeRanch!

No offences, but the code given at blog link is horribly formatted.

Due to that reason, I couldn't figure out which is real 'line 812' - where the program is giving NPE.

Can you please post that part of code?

Also, please UseCodeTags while doing so (paste the code, select code part and hit 'Code' button at top of post editor).


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Anayonkar Shivalkar wrote:Hi Tawi,

Welcome to CodeRanch!

No offences, but the code given at blog link is horribly formatted.

Due to that reason, I couldn't figure out which is real 'line 812' - where the program is giving NPE.

Can you please post that part of code?

Also, please UseCodeTags while doing so (paste the code, select code part and hit 'Code' button at top of post editor).


I tried to but I failed because the site want no more than 120 characters code, so, what should I do? Just copy and paste it to your netbeans ok?
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2372
    
  28

Format your code before posting. The harder you make it for people to help you, the less help you will get
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Jayesh A Lalwani wrote:Format your code before posting. The harder you make it for people to help you, the less help you will get


How can I do that? I mean, what should I do to format my code before I post it?
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2372
    
  28

Using the editor that you use to write java code. Doesn't take long to scan through the file to find long lines and wrap them before posting.
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Well, I modified and put some comments to the code to show the line number. Please help me.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2285
    
  49
If you want help I suggest you do as people have already asked and post properly formatted code in this thread remembering to UseCodeTags.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18825
    
  40

Tawi Oei wrote:I cannot write the code in this forum, please open http://www.tawijakarta.blogspot.com to see my code.


Just took a look at the code in the blog.... and wow... people weren't kidding when they said that it wasn't readable. There is no formatting whatsoever -- in fact, there are whole sections where there are no line breaks at all.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Henry Wong wrote:
Tawi Oei wrote:I cannot write the code in this forum, please open http://www.tawijakarta.blogspot.com to see my code.


Just took a look at the code in the blog.... and wow... people weren't kidding when they said that it wasn't readable. There is no formatting whatsoever -- in fact, there are whole sections where there are no line breaks at all.

Henry


http://uploading.com/cbb19743/ProgramTesisBaru-java

Ok, that is the link, just download the code in that file from that link because I cannot use any attachments ok?
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2285
    
  49
Copy and Paste your code into your post. Highlight the code for each class you are pasting in and click on the code button in the toolbar.
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Tony Docherty wrote:Copy and Paste your code into your post. Highlight the code for each class you are pasting in and click on the code button in the toolbar.


I do not know how to do that, just download the file and open it please? I need to finish this work as soon as possible and sorry if you feel not good because of this. This is not an offence ok?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18825
    
  40

Tawi Oei wrote:I do not know how to do that, just download the file and open it please? I need to finish this work as soon as possible and sorry if you feel not good because of this. This is not an offence ok?


In a world full of viruses and malware, I think that many people will feel very uncomfortable going to a file sharing site. If you don't want to post the code here, that is your choice. There is nothing wrong with not wanting to do it... However, keep in mind that everyone here is a volunteer, and there are many questions being asked here. So, I can easily see that people would prefer to answer the questions that doesn't require them to register on another site.

Good luck though. Maybe another rancher is willing to download and look into it for you.
Henry
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Henry Wong wrote:
Tawi Oei wrote:I do not know how to do that, just download the file and open it please? I need to finish this work as soon as possible and sorry if you feel not good because of this. This is not an offence ok?


In a world full of viruses and malware, I think that many people will feel very uncomfortable going to a file sharing site. If you don't want to post the code here, that is your choice. There is nothing wrong with not wanting to do it... However, keep in mind that everyone here is a volunteer, and there are many questions being asked here. So, I can easily see that people would prefer to answer the questions that doesn't require them to register on another site.

Good luck though. Maybe another rancher is willing to download and look into it for you.
Henry


I guess you don't need to register to that site.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2285
    
  49
Tony Docherty wrote:Copy and Paste your code into your post. Highlight the code for each class you are pasting in and click on the code button in the toolbar.

I do not know how to do that

Sorry but which part of my instructions do you not understand?

, just download the file and open it please?

I don't download files as a rule, so unless you post the code here I'm out.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18564
    
    8

Oh dear. You haven't had any training at all in object-oriented design (I can tell because you asked "How to call a class from a class?"). And yet you are writing a Swing application which already has something like 1,000 lines of code. So this promises to be a bad situation.

Realistically, you can't expect people to look at 1,000 lines of code and help you fix it when it's broken. Especially when it's badly-formatted, as apparently it is.

So what I'm going to suggest is this: Take your code and remove everything which isn't related to the error you are currently stuck with. When you reduce your code to something small (less than 50 lines of code would be ideal) which still exhibits the problem, then post it here. I'm assuming that you didn't really mean to say that you don't know how to copy and paste code, but if that's really the case then let us know and somebody can explain the basics to you.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18825
    
  40

Tawi Oei wrote:
I guess you don't need to register to that site.


You also forgot to mention the adult-specific ads that pop up ...? Sheesh....


Anyway, you have code lines that are ridiculously long... such as this one...

JOptionPane.showMessageDialog(null, "Nama Dokter Belum Dimasukkan", "Dokter atau Kata Sandi tidak Ada", JOptionPane.INFORMATION_MESSAGE);

You should break it up .... like ...

JOptionPane.showMessageDialog(null, "Nama Dokter Belum Dimasukkan",
----------------------------------- "Dokter atau Kata Sandi tidak Ada",
----------------------------------- JOptionPane.INFORMATION_MESSAGE);


then you can add the code tags...



The forum software don't like code lines that are too long, as those lines are generally not readable if the browser has to break it up, or if a horizontal scroll bar has to be used.

Henry
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

i would go further:

String a = "Nama Dokter Belum Dimasukkan";
String b = "Dokter atau Kata Sandi tidak Ada";
JOptionPane.showMessageDialog(null,a, b, JOptionPane.INFORMATION_MESSAGE);


SCJP
Visit my download page
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95


Ok I revised the code. Here is the code, so? How to remove below error messages?

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at PrgTesisServer.FrameBaru.<init>(ProgramTesisBaru.java:821)
at PrgTesisServer.ProgramTesisBaru$1.lanjut(ProgramTesisBaru.java:102)
at PrgTesisServer.ProgramTesisBaru$1.actionPerformed(ProgramTesisBaru.java:99)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14144
    
  18

A NullPointerException means that you are trying to dereference a variable that is null. For example, you call a method on a variable that is null.

Note that the stack trace tells you exactly in which line it happens; in this case, line 812 of your code.

In your code, line 812 is this:

If this throws a NullPointerException, it means that isi is null.

Check your code to see where isi is initialized. I see that it happens in line 759, where you call getContentPane() to initialize it.

Note that that line is executed when your FrameBaru object is being initialized. Most likely, the frame does not have a content pane yet at that moment, so getContentPane() returns null.

Remove line 759.

Just before line 812, add the line:


This will make isi a local variable in the constructor instead of a member variable.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Jesper de Jong wrote:A NullPointerException means that you are trying to dereference a variable that is null. For example, you call a method on a variable that is null.

Note that the stack trace tells you exactly in which line it happens; in this case, line 812 of your code.

In your code, line 812 is this:

If this throws a NullPointerException, it means that isi is null.

Check your code to see where isi is initialized. I see that it happens in line 759, where you call getContentPane() to initialize it.

Note that that line is executed when your FrameBaru object is being initialized. Most likely, the frame does not have a content pane yet at that moment, so getContentPane() returns null.

Remove line 759.

Just before line 812, add the line:


This will make isi a local variable in the constructor instead of a member variable.


Ok, its done. The problem is I get some error messages which are:


Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at PrgTesisServer.FrameBaru.<init>(ProgramTesisBaru.java:820)
at PrgTesisServer.ProgramTesisBaru$1.lanjut(ProgramTesisBaru.java:102)
at PrgTesisServer.ProgramTesisBaru$1.actionPerformed(ProgramTesisBaru.java:99)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

What should I do? Why do I get blank screen after I press lanjut button? Why don't all of the buttons I put in isi show? How to call a class from a class, a class from a method, and a method from a class? I cannot copy and paste the code again, can any folks help me with this? How to make a program with dual frames?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

When you assign a new JTextField[20][2] to jawab that creates an array that contains 20 arrays which each two null elements. In other words, yes you have a "two-dimensional" array (actually array of arrays), but all of the elements are still null. You need to assign those:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18825
    
  40

To be blunt, at this point, it may be better to stop giving the direct answer, and teach the OP on how to figure it out ... otherwise, this error will keep happening.

Tawi Oei wrote:
Ok, its done. The problem is I get some error messages which are:


Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at PrgTesisServer.FrameBaru.<init>(ProgramTesisBaru.java:820)
at PrgTesisServer.ProgramTesisBaru$1.lanjut(ProgramTesisBaru.java:102)
at PrgTesisServer.ProgramTesisBaru$1.actionPerformed(ProgramTesisBaru.java:99)



If you look at the stack trace, you will see that it is happening in the constructor of the PrgTesisServer.FrameBaru class. Also, it is near (at or before) line 820 in the source (ProgramTesisBaru.java) file.

The best thing to do is to locate the line in question -- and add a bunch of printout to see the value of the components. You need to locate what is null (likely what is not initialized, or set incorrectly), and then fix it.

Other things to note, which may help, the next line (of the stack trace) tells you the location where the constructor was called -- which can be used to find a location to put printouts before the constructor is called. It should also be noted that the constructor is the top of the trace, which means that there is no reason to go into other constructors and methods, that this constructor is calling -- just look at what is returned... and finally, of course, putting printouts into the code will affect the stack trace, so always use the newest one.

Henry
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Please open http://www.tawijakarta.blogspot.com and look at Java Program II. I got null pointer exception, how to solve this? I cannot copy and paste the code to this forum because I cannot make this site to post my message to the forum.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2285
    
  49
I cannot copy and paste the code to this forum because I cannot make this site to post my message to the forum.

That's a poor excuse for persisting with using a blog, everyone else manages to post code here. Taking the time to reduce your line lengths to less than 120 chars so you can post here will ensure you get a better response to your questions. The more effort you make, the more effort others are likely to make to help you.
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95


Ok here are the codes, what should I do? Here are the error messages that I get:

Exception in thread "main" java.lang.NullPointerException
at programtesisbaru.ProgramTesisBaru.<init>(ProgramTe sisBaru.java:66)
at programtesisbaru.ProgramTesisBaru.main(ProgramTesi sBaru.java:536)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 minute 9 seconds)
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3528
    
  15
First of all : indent. It makes your code a lot easier to read.

Your stack trace is showing that the NPE happens at line 66. Look at line 66 and decide which variables are being dereferenced (being used to access one of their fields). Now try and work out which of those variables is null.

Joanne
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Joanne Neal wrote:First of all : indent. It makes your code a lot easier to read.

Your stack trace is showing that the NPE happens at line 66. Look at line 66 and decide which variables are being dereferenced (being used to access one of their fields). Now try and work out which of those variables is null.


I wrote some codes to solve this but They failed, What should I do?

By the way, why can't I access this forum from computer at my home?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38765
    
  23
Tawi Oei wrote: . . . I wrote some codes to solve this but They failed, What should I do?
Follow Joanne’s suggestions. By reading the line she quoted, you should be able to work out what is null.

Tawi Oei wrote:By the way, why can't I access this forum from computer at my home?
Don’t know. How could we know?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3528
    
  15
Tawi Oei wrote:I wrote some codes to solve this but They failed, What should I do?

ItDoesntWorkIsUseless.

As you have tried to fix it, we assume you know what the problem is i.e. You know which variable is null. The normal way to fix a null variable is to assign something to it.

Probably a good place to start is for you to tell us which variable you think is null and what you did to fix this. We can then tell you if you are moving in the right direction.
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Rob Spoor wrote:

I tried to apply the codes that are similar with below codes but they failed, so what should I do?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3528
    
  15
Do the line numbers in your source file match the line numbers in your previous post ? If they do then initialising the elements of jawab is not going to fix the problem because that variable is not used on line 66.

Note: you may still need to initialise jawab, so don't take this code out. It's just that I don't think that is the current problem.


Edit: Okay. I just noticed that you were quoting Rob's earlier post there.
You need to look at the error messages more carefully. Your first NPE error was at line 812. Rob's code probably fixed that.
You now have a different problem. It's still a NPE but it's at line 66. That's the line you need to investigate.
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95


Well, I tried this on my prior codes but failed. What should I do? NetBeans said that the variable was defined before, so?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3528
    
  15
Tawi Oei wrote:

Well, I tried this on my prior codes but failed. What should I do? NetBeans said that the variable was defined before, so?

Where have you put these lines ? Do you still get the exact same error message after adding these lines ?
Note that Java is case sensitive. Your variable is called kriteria, but you appear to be using Kriteria in these new lines of code
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Oops sorry, I was putting kriteria not Kriteria but the NetBeans said that the variable is already defined, so what should I do?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41815
    
  62
Search your source code carefully for whichever variable name you have declared twice. NetBeans tells you which one that is ("kriteria", I guess ?), so it shouldn't be hard to find the duplicate declaration. I might take a look myself, but 750 lines of unformatted code is way too much to expect anyone to go through.

I also have to ask: the code looks like it works with medical data. You seem comparatively inexperienced when it comes to Java development; will someone more senior do a code review once it is done? In handling such data -which presumably might affect people's health- great take care must be taken, and with all due respect, your approach to development does not seem methodical enough to guarantee solid code at the end.


Ping & DNS - my free Android networking tools app
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Please open http://www.tawijakarta.blogspot.com and see Java Program III article. Why do I get NullPointerException?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3528
    
  15
Tawi Oei wrote:Please open http://www.tawijakarta.blogspot.com and see Java Program III article. Why do I get NullPointerException?

You've already been told several times that the code on your blogspot is practically illegible. Nobody is going to be able to answer your question by looking at that.

You've also been told how to diagnose a NullPointerException from a stack trace. You need to ShowSomeEffort. The minimum you need to do is find the line of code that the NPE is happening on (the stack trace tells you this) and work out which variable is null.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please help with NullPointerException