• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Executing Old Code

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm having a very weird problem and I wasn't sure what to call it so pardon the vagueness of the Subject title. Also, I apologize if this question was asked here before but my search was unsuccessful (not to mention, I wans't sure what to search for in the first place)

I have a main class in which I have written some code. However, some of the lines were causing problems so I took them out. After saving when I try to recompile, the compiler is still compiling the old file in its memory. i.e. it tries to compile code that is not even in the new main file, now that I have changed it.
Thus, I get a null pointer exception.

The output is shown below and I'm not sure if it would be of any help to put in the code from main file. Currently my Main.java class has less than 70 lines of code. But the error is suggesting something in line 81. Has anyone else faced this before? How do I solve this?





Thanks in advance for your help.





 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope, the compiler doesn't keep anything in its "memory". Somehow you are either not compiling and running the file that you think you are, or your class file is not being updated with the new code like you think it is.
 
Steve De Costa
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Nope, the compiler doesn't keep anything in its "memory". Somehow you are either not compiling and running the file that you think you are, or your class file is not being updated with the new code like you think it is.



Well, there's only one main file in the package that I'm compiling. And every time I open the file, I see the same updated code. This is the strangest thing I've ever come across. Any suggestion on how do I fix it?


I tried and copying and pasting the code into a a new file called NewMain.Java within the same Package.

It just brings a window titled "Java Virtual Machine Launcher" with the following error message.

"Could not find the main class. SasCode.NewMain. Program will exit now."

Any suggestions on how do I fix this?
 
author
Posts: 23951
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

Steve De Costa wrote:
I tried and copying and pasting the code into a a new file called NewMain.Java within the same Package.

It just brings a window titled "Java Virtual Machine Launcher" with the following error message.

"Could not find the main class. SasCode.NewMain. Program will exit now."



This actually confirms that the new compiled code isn't the code that is running -- and that you are running some old class files somewhere.

Anyway, I recommend that you traverse all the directories in your classpath, to see if you can find the old code. You also need to add the location that you are using to compile with in your class path too, as it doesn't seem to be able to find your new stuff, when you renamed it.

Henry
 
Steve De Costa
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:
This actually confirms that the new compiled code isn't the code that is running -- and that you are running some old class files somewhere.

Anyway, I recommend that you traverse all the directories in your classpath, to see if you can find the old code. You also need to add the location that you are using to compile with in your class path too, as it doesn't seem to be able to find your new stuff, when you renamed it.

Henry



I actually tried that. I try debugging line by line. But a Point comes when its trying to go somewhere and ends up giving a null pointer exception. Why the hell would it be looking somewhere else in the first place.

 
Henry Wong
author
Posts: 23951
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

Steve De Costa wrote:Why the hell would it be looking somewhere else in the first place.



That is how it supposed to work. If you set a class path, either via environment variable or command line, it will use that for the roots of the classes. And if the current directory isn't in the class path, then it won't search your current directory.

Anyway, care to tell us... (1) if you have a CLASSPATH environ set? (2) how you are compiling (3) you directory structure and (4) where the java and class files are located, and maybe we can see something.

Henry
 
Steve De Costa
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Steve De Costa wrote:Why the hell would it be looking somewhere else in the first place.



That is how it supposed to work. If you set a class path, either via environment variable or command line, it will use that for the roots of the classes. And if the current directory isn't in the class path, then it won't search your current directory.

Anyway, care to tell us... (1) if you have a CLASSPATH environ set? (2) how you are compiling (3) you directory structure and (4) where the java and class files are located, and maybe we can see something.

Henry



Hey Henry,

Thanks for taking a stab at this. I am a noob at Java Programming, and I'm just coding something for a project. SO I'll try answering your questions to the best of my knowledge.

(1) I'm not sure if I ever did it. I know I added some external jar's into my project. I'm coding this all in eclipse.
(2) In eclipse I just press "Ctrl+F11" to compile. I've even tried right clicking on the new main file to run it as a java application but I don't think it had any effect.
(3) In the Source package, I created a sub package called StatsCode. So basically, the structure is give below.
Main project -> src package -> StatsCode Package -> NewMain.java
(4) Java is essentially an eclipse folder that I have placed in my c:\Program Files. The Files are stored on an external USB drive (H:). Not sure if giving the exact location will help in this case....


Did I get you the answer you were expecting?
 
Steve De Costa
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ANyone???
 
Henry Wong
author
Posts: 23951
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

Steve De Costa wrote:
(1) I'm not sure if I ever did it. I know I added some external jar's into my project. I'm coding this all in eclipse.



Steve De Costa wrote:
I tried and copying and pasting the code into a a new file called NewMain.Java within the same Package.

It just brings a window titled "Java Virtual Machine Launcher" with the following error message.

"Could not find the main class. SasCode.NewMain. Program will exit now."



Here's the good news. What you described can't really happen with an IDE. IDEs are very good about keeping your packaging and classpath, all set correctly. You can't create a new class with a main, and the IDE can't find it.

Here's the bad news. When it does happen, it means you corrupted something. And quite frankly I don't have a clue how to fix this (within eclipse). The few times that this happened to me, and the project wasn't in source code control, I delete the eclipse project meta data, fixed everything from the command line, and reloaded the java sources into a new project.

Henry
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps you should learn how to do things outside the IDE?
 
Don't destroy the earth! That's where I keep all my stuff! Including this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic