• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Please help with NullPointerException

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Tawi Oei
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I modified and put some comments to the code to show the line number. Please help me.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want help I suggest you do as people have already asked and post properly formatted code in this thread remembering to UseCodeTags.
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Tawi Oei
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 28360
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
 
Tawi Oei
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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)
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tawi Oei
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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)
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tawi Oei
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Marshal
Posts: 80221
424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops sorry, I was putting kriteria not Kriteria but the NetBeans said that the variable is already defined, so what should I do?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tawi Oei
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please open http://www.tawijakarta.blogspot.com and see Java Program III article. Why do I get NullPointerException?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Squanch that. And squanch this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic