Nullpointer exception... any help would be appreciated
In advance, I apologize for any ignorance which I may obviously have... I'm in the process of learning Java, and am used to C/C++... In any case, I'm running into a nullpointer exception while 'compiling', which I'm having trouble figuring out... I'll list everything below, but this message will be rather long, as I will try to include everything I can. For this reason, I will ask my questions here, at the top:
1) A null pointer exception, I believe, is generated when something is being referenced which is currently null, for example "a=null; a.b;" yields a null pointer exception. However, is there any other way that one is generated?
2) Are there methods to figure out what/why something is null other than simply looking at it? As shown below, it seems that just looking at it runs you in a circle from line to line, file to file, which leads you back to the beginning where nothing is actually null... (I'm probably just not seeing it, but that seems to be what's happening to me)
So now, on to the actual code:
The following is a printout of the debugging info:
~/bin/jdk*/bin/java -classpath classes jamie.Main
java.lang.NullPointerException
at jamie.Main.Sys_Log(Main.java:110)
at jamie.Main.Setup(Main.java:142)
at jamie.Main.main(Main.java:54)
Exception in thread "main" java.lang.NullPointerException
at jamie.Main.Sys_Log(Main.java:110)
at jamie.Main.Shutdown(Main.java:182)
at jamie.Main.main(Main.java:92)And a short excerpt of each. (*) indicates line which error originates:
20 ) private static Log sys_log;
108 ) static void Sys_Log(String msg)
109 ) {
110*) sys_log.Log(msg);
111 ) }
142*) Sys_Log("Server warming up...");
182*) Sys_Log("Server shutting down...");
50 ) public static void main(String[] args)
51 ) {
52 ) try
53 ) {
54*) Setup();
85 ) catch(Exception e)
86 ) {
87 ) e.printStackTrace(System.out);
88 ) err_log.Log(e.toString());
89 ) }
90 ) finally
91 ) {
92*) Shutdown();
93 ) }Now, various things that I have tried, and their result (you can probably skip this section, as these were mostly futile efforts):
What seems odd to me is that the initial error is on line 110, which is the logging function Sys_Log. Since it's a null pointer exception, I would assume that sys_log is null? and thus in calling Log we're generating that error... I'm not entirely sure that that makes sense, though. Additionally, and what I find odd, is that if I change it to what I will list below, I get a slew of other seemingly unrelated problems:
20 ) private static Log sys_log;
108 ) static void Sys_Log(String msg)
109 ) {
110#) if (sys_log!=null)
111 ) sys_log.Log(msg);
112 ) }This results in a problem with function Err_Log, which I change the same way, resulting in the following:
java.lang.NullPointerException
at jamie.Area_LUL.Load(Area_LUL.java:23)
at jamie.Main.Setup(Main.java:161)
at jamie.Main.main(Main.java:55)
Exception in thread "main" java.lang.NullPointerException
at jamie.Main.Shutdown(Main.java:186)
at jamie.Main.main(Main.java:93)In Main.java the following lines are generating the error:
160 ) lul = new Area_LUL();
161*) lul.Load();And in Area_LUL.java I also have the following:
14 )class Area_LUL implements LoaderUnloader
15 ){
16 ) public void Load()
17 ) {
18 ) try
19 ) {
20 ) areadir = new File("./areas/");
21 ) SAXParser p = SAXParserFactory.newInstance().newSAXParser();
22 )
23*) for(File curr : areadir.listFiles(new Area_Filter()))
24 ) {
25 ) p.parse(curr, new XMLParser());
26 ) }
27 ) }Where in the above, the for statement is generating the null pointer exception... which would tell me that areadir is null, however it is defined as new File("./areas/"); Also, lul (defined as new Area_LUL(); is generating the same error, though it is clearly defined in Area_LUL.java at the top of the last excerpt.
Also, LoaderUnloader is defined in another file as follows:
interface LoaderUnloader
void Load();
void Unload();
}which are defined in Area_LUL in Area_LUL.java .
A major theory which I currently have is that the compiler is beginning with my main.java file, and not seeing the class definition in another file, and thus attributing the class obj I create as null, which is causing the error, but I also am not sure if this is possible...
My imports for Main.java are as follows:
package jamie;
import java.io.*;
import java.util.*;I'm not entirely sure what the package is including, however I do have a jamie.jar file in another directory (../../dist) (could be referencing that?). Also, to compile the source I am using the following command:
~/bin/jdk*/bin/java -classpath classes jamie.MainHowever my classpath (I believe) isn't set to include all my files in the given directory. I wouldn't believe that this would be an issue, however if it could possibly be causing this, I can figure out how to set it properly. Also, this should mean I'm starting with Main.java, and perhaps I am right in concluding that it isn't referencing Area_LUL in another file properly, which is setting it as null?
In any case... Any help would be greatly appreciated. This has been a bit of a struggle for about a month now, trying various resources, moving things around, etc... Thanks so much for your time in reading,
-Jess
I'm not able to follow the program flow from your post. Please create a small standalone program that exhibits the problem and post that back here.
Your assumption re a NPE is correct, that's the only way they're generated.
There are no "canned" methods to resolve NPEs. The best solution is to put System.out.println statements for all of the involved objects and variables immediately preceeding the error line (in this case, 110) and something will show null. Usually that's enough info to backtrace to the real cause.
Similar Messages
-
Downloaded Yosemite and since then cannot connect to internet or bluetooth mouse - was advised to delete system configuration file from the hard drive and since then cannot start up computer. Any help would be appreciated - cheers.
Boot the MBP with the OPTION+COMMAND+R keys down. The result should be a display showing a revolving globe. By following the instructions, you will be able to reinstall the original OSX. Then you may reinstall Yosemite.
A solid Internet connection will be required.
Ciao. -
I have OS 10.5.8 and am unable to run ITunes or IPhoto. I can reinstall I tunes, but it says I need the newest version of QuickTime, which I already have. Any help would be appreciated!
Hello Esther,
Do you have QT v7.7?
http://support.apple.com/kb/DL761
And iTunes v10.6.1?
http://support.apple.com/kb/DL1426 -
I have a new iphone and went into Itunes and it said my new iphone needed a software update. I let it do this and now the apps that I put on won't work and when pressed just flash on then off the screen. I paid £20 for one of them so any help would be appreciated.
Memory Map: http://www.memory-map.co.uk/iphone/
0870: http://www.simonmaddox.com/
Viber: http://support.viber.com/home
VoucherCloud: http://questions.vouchercloud.com/ -
I can see the Application folder in the Finder window but can't seem to get it back on to my dock.
Any help would be appreciated it!Close all windows and quit all applications.
Launch Finder by clicking the Finder icon in the Dock.
Right click the "Application" folder and select "Get Info".
At the bottom of the resulting window there will be a blue folder icon in the preview section.
Drag the whole window to the right side of the desktop,closer to the Dock.
Now drag the blue preview folder to the Dock right of the separator line.
Right click the folder icon and select "Folder" under "Display as" if it is not shown as folder.
Best. -
Using my USB, my ipod touch 2 is not recognized in Windows Vista or i tunes. If I connect it to my wifes Xp, ( where it was before) , it still charges up ( i tunes has been uninstalled. Any help would be appreciated. I have reinstalled itunes.
http://support.apple.com/kb/TS1538
There have been some problems accessing pages on the Apple web site. If the hyperlink gives you a "We're sorry" message, try again. -
I am getting the message "The windows installer Service could not be accessed when trying to install Itunes on my new computer, any help would be appreciated.
Hey there Frank0619,
If you have not been able to install iTunes because the Windows Installer service is not available, I would recommend the troubleshooting in the following troubleshooting to help.
Issues installing iTunes for Windows
These in particular:
Make sure you have an administrator account.
To install iTunes, you'll need to log in to your computer with an administrator password. If you're not sure if you have an administrator account, read Windows 7: How do I log on as an administrator? You could also refer to your computer's help system, contact your IT department, or visit support.microsoft.com for assistance.
Install the latest Microsoft Windows updates.
To download the latest updates, visit the Microsoft Windows Update website. iTunes for Windows requires Windows XP, Windows Vista, Windows 7, or Windows 8 with the latest Service Pack installed. If you can’t install the updates, refer to your computer's help system, contact your IT department, or visit support.microsoft.com for assistance.
Download the latest version of iTunes.
The latest version of iTunes can be downloaded at http://www.apple.com/itunes/download/.
Disable conflicting software.
Some Windows background processes can cause issues for other programs and processes. These conflicts can prevent applications, such as iTunes, from installing. Disable conflicting processes by starting your computer using MSConfig:
Using Msconfig to troubleshoot conflicts in Windows XP
Using Msconfig to troubleshoot conflicts in Windows Vista, Windows 7, and Windows 8
Some security software made by other companies can't be disabled using MSConfig. If you've installed security software and you're having issues installing iTunes or QuickTime for Windows, you might need to disable or uninstall security software to resolve installation issues.
Restart your computer.
Install iTunes.
Thank you for using Apple Support Communities.
All the best,
Sterling -
Apple Composite AV Cable no longer working on Ipad2 after ios8 update. I'm only getting sound no video can you revert back to ios7 or buy a cable that will work any help would be appreciated
ThanksThe 30-pin connector on the iPhone 4 dock might not have all the connector pins to do video.
I'm 99% sure the Universal Dock does have the pins (and therefor supports video out). -
Hi
I'm using a 3GS (4.3.3) and itunes 10 2.2.12
When trying to sync my music my phone begins the syncing process, back up and preparing etc. Once it begins actually syncing it seems to get stuck on song 2 of 1500. After about 5-10mins a message appears saying song 2 of 1500 can not be copied because it can not be copied or read. Thats it. It doesn't try to sync the rest it just stops. The music is definitely available and it seems to have no problems syncing any podcasts. Any help would be appreciated. ThanksRemove the song in question from the sync list and see if the rectifies the problem.
If it does, then iTunes believes the song no longer exists on your drive and that will need to be corrected. -
Just installed a HP Color Laserjet CM2320nf MFP printer, at the same time I upgraded to Lion. It prints fine, but I cannot use the scan functions. I downloaded the most recent driver! Any help would be appreciated.
HP says that the drivers for your all in one print/scanner are downloadable from apple. For the scanner to use preview. image capture or the scan icon from the print driver queue. I don't know how old your HP is, but I know that the newer Os from apple don't support a lot of older printers. You might be able find a third party driver that could work.
-
hi - i'm a newbie - what is the quickest way to move all my iTunes music, video, etc. to a new computer? any help would be appreciated. thanks.
p.s. i purchased a belkin transfer cable - will that work? i have an iPod Touch.You copy it from one computer to the other.
Type "move itunes library" into the google search bar.
You have posted in the iphone forum. -
My old computer crashed and I am trying to download Adobe X Pro on my computer. I have tried to download and the only download I can find is the Adobe XI Pro. Any help would be appreciated. I have the product key but it's not deactivated on my old computer.
if you need to deactivate, contact adobe support
https://helpx.adobe.com/contact.html
Downloads available:
Suites and Programs: CC 2014 | CC | CS6 | CS5.5 | CS5 | CS4 | CS3
Acrobat: XI, X | 9,8 | 9 standard
Premiere Elements: 13 |12 | 11, 10 | 9, 8, 7
Photoshop Elements: 13 |12 | 11, 10 | 9,8,7
Lightroom: 5.6| 5 | 4 | 3
Captivate: 8 | 7 | 6 | 5
Contribute: CS5 | CS4, CS3
Download and installation help for Adobe links
Download and installation help for Prodesigntools links are listed on most linked pages. They are critical; especially steps 1, 2 and 3. If you click a link that does not have those steps listed, open a second window using the Lightroom 3 link to see those 'Important Instructions'.
window using the Lightroom 3 link to see those 'Important Instructions'. -
Hi, I have an Adobe CC single App subscription at €25. per month, why do I now have to pay another 12.99 to get Lightroom CC? any help would be appreciated, thanks.
Hi there
You currently have a single app membership for Photoshop. You might want to consider changing to the Creative Cloud Photography plan if you wish to have Photoshop CC + Lightroom CC - see Creative Cloud pricing and membership plans | Adobe Creative Cloud
Photoshop Help | Differences between Photoshop and Creative Cloud Photography Programs
Thanks
Bev -
I can't run the powerpoint slideshow on macbook air (mavericks). It just says powerpoint encountered an error and needs to quit, when I select the slideshow option. any help would be appreciated.
You might want to consider starting a new discussion. Since this one is marked solved, less people are likely to look at it.
You can include a link to this discussion. -
Hi, i had created a form on adobe forms central, but i don't have access to the results now. any help would be appreciated.
Hi massif76198910,
I don't see that you had a paid FormsCentral account. Were you using the free account? If so, you should still have access to the form until FormsCentral is retired on July 28 2015,
Are you able to log in? Or do you get an error when you try to log in to your account? Please try clearing the browser cache, or logging in via a different browser.
Best,
Sara -
I am trying to sent an e-mail to a large distribution list, without everyone appearing in the "To" field. I do not want anyone else to see who I am sending the e-mail to. Any help would be appreciated?
Mail Preferences, Composing:
Uncheck the option to show all recipients.
Maybe you are looking for
-
hi I want to use text2D as texture for a sphere..How can I do that..!! thanks a lot
-
Connecting various old SPARCstations to a sony/SGI gdm20-D11
Hi all, I have aquired quite a collection of old sparcstations here, and I would like to fire them up and try and get them working again. As can be seen from the subject, I'm trying to get an output on an SGI monitor, which i though was not possible,
-
Reminders and how to get them into MS Outlook 2007
Has anyone worked this one out. I have tried everything i know but to no avail. Thanks
-
My Canon 6D pictures will not preview in latest Adobe CC suite
This is despite thumbnails appearing - this happens in both Lightroom CC and Bridge CC - can anyone please explain or point out what I might be doing wrong - its not as if the 6D is brand new? Regards AW
-
I CAN'T DOWNLOAD THE FILMS RENTED. THE DOWNLOAD IS STOPPED FAR BEFORE THE DOWNLOAD IS COMPLETED AND DISAPPEAR THE POSSIBILITY TO DOWNLOAD AGAIN