File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Executing Old Code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Executing Old Code" Watch "Executing Old Code" New topic
Author

Executing Old Code

Steve De Costa
Ranch Hand

Joined: Jun 04, 2007
Posts: 33
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.





Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve De Costa
Ranch Hand

Joined: Jun 04, 2007
Posts: 33
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?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18531
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Steve De Costa
Ranch Hand

Joined: Jun 04, 2007
Posts: 33
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
Sheriff

Joined: Sep 28, 2004
Posts: 18531
    
  40

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

Joined: Jun 04, 2007
Posts: 33
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

Joined: Jun 04, 2007
Posts: 33
ANyone???
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18531
    
  40

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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Perhaps you should learn how to do things outside the IDE?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executing Old Code
 
Similar Threads
Passed with 81%
cleared scbcd 81%
81%!& my exp.
I passed today! 81%
Passed with 81%