I think this is going to turn out to be a pretty straightforward answer. It is one of those things that after you have used an IDE for a few months, you just run your class and all is well. I am learning Java/Eclipse and can't find an answer to this anywhere on the web.

Usually when I want to run a class I select Run from the tool bar and the current class is run. Sometimes I will Rt Click the class > Run and it runs. Then when I want to run another class I follow the above steps and that new class runs.

1 out of 20 times I run my class as described above and my class does not run. The console tab lists a different class that was run, one I was running earlier in the day.

How do I get Eclipse to stop running the old class, and run the one I Rt click > Run As on? I'm sure I have inadvertently modified how Eclipse works with the previous or current class.

I just shut Eclipse down and restarted it. I clicked the green right arrow in the toolbad and it ran the previous class. Then I Rt. Click > Run configurations the new class and it shows me the Run Configurations window, with Name: "OldClass". Under Main Class: if I click Search, my new class is not listed. I'm sure this is closer to the problem.

Thanks in advance,

willisduke3

02-29-2012, 07:11 PM

KevinWorkman

Re: Eclipse runs a previous class and won't run the current class

Have you tried doing a refresh/clean?

Does it work if you run from the command prompt?

02-29-2012, 09:54 PM

willisduke3

Re: Eclipse runs a previous class and won't run the current class

Quote:

Originally Posted by willisduke3

I think this is going to turn out to be a pretty straightforward answer.

As I said... I know one thing that causes this issue, but I think there are other causes also becuase most of my training applications have had one class and they have all had a main method. The problem in this case was that I ran one class in a four class application without realizing there were three more classes in the application. The class I ran did not have a main method. Once I loaded the other three classes and started by running the class with the main method, it ran properly.

willisduke3

01-22-2015, 07:04 PM

samuelsumanth

Re: Eclipse runs a previous class and won't run the current class

I was facing the same issue, and after searching on several blogs which seemed to be talking way too techincal.. And some even called it as being an Eclipse bug.

I found the simple resolution to my issue in @Willisduke3's response.. Basically my class did not have a main method (I had mistyped main as mail) and hence the execution was mapping to the previously run valid class which had a valid main method.

Once I ensured that my current program had a main method, the execution mapped to my current class and gave me the desired output.

Thank You. :)

01-22-2015, 07:07 PM

jim829

Re: Eclipse runs a previous class and won't run the current class

This thread is almost three years old (but I'm glad your resolved your problem).