开发者

Java program strange behavior, how to fix it?

My notebook has Intel CPU, running Windows Vista. My program looks like this :

public class Tool_Lib_Simple
{
  public static void main(String[] args)
  {
    System.out.println("123");
  }
开发者_如何学运维}

When I run it, I expect to see : "123", but the output was : "Hi NM : How are you NM ?" which was the old output from two days ago before I changed my program. If I copy this program into another project in Netbean 6.7, it will run correctly and output "123", and if I change the program name from "Tool_Lib_Simple" to something else, it will also output "123", but just not under the name of "Tool_Lib_Simple" in the current project's src directory, I've deleted the "build" directory and did re-compile, re-build, it still gives me "Hi NM : How are you NM ?" as a result, seems to me the old version of my program is saved in the hard drive or ram and got stuck there, I've programmed many years, hardly ever encounter this kind of problem, how to fix this ?

Frank


Edit :

As Brian suggested below , I ran it from command line :

java -cp "C:...\build\classes" Tool_Lib_Simple

The result is : "123"

Now, it seems NetBeans6.7 (I also tried 6.8, same result) is causing this, I have deleted "Tool_Lib_Simple.java" from the project, copied it back from another project, but the result is still the same, it's pointing to an older version, how can I overcome this problem ? [ I tried the clean & rebuild many times, didn't work ]


I would recompile it. or compile it manually. But in Netbeans I think you can click on the project and click build or clean and build.


How are you running it ? Try (from the command line)

java -cp {path to your class} Tool_Lib_Simple

and that should work. I'm guessing either your personal classpath or your IDE classpath is pointing to another instance. find is probably of use here, to find different instances of your class.


Netbeans offers the option to clean and build which should remove old compiled classes and only run new code. From the netbeans toolbar click the icon that looks like a hammer and a broomhead.


Right click on your new project and select 'Set Main Project' then press F6 and you should see the correct output. Or if want to run the current file that you are editing press SHIFT F6. (Or how are you starting the program via mouse or keyboard?)

If that not helps try to disable compile on save in the properties (right click the project).

If that not helps maybe you choose the wrong package name of the file? Try to fix this.

Link to your zipped project here and we could further assist to a solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜