0

I figured the error was due to my Path or ClassPath being incorrect, but I used Java for months with no problem as I set the Paths when I downloaded Eclipse Neon. I also seen being in packages can cause it, so I created classes outside of packages and still got the error.

The weird thing is some classes I create run fine, but others won't, and they'll be the exact some code in the same package, but only have different names.

Here is the exact example, HelloWorld works, but parserpractice doesn't, and they are both in the exact same location:

package ParserPractice;

public class HelloWorld {

    public HelloWorld() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) {
        System.out.println("Hello");

    }

}

package ParserPractice;

public class parserpractice {

    public parserpractice() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) {
        System.out.println("Hello");
    }
}

My Path and ClassPath environment variables on Windows 7 are:

Path variable name: C:\Program Files\Java\jdk1.8.0_101\bin;C:\Program Files\Java\jre1.8.0_101\bin;

ClassPath variable name: C:\Program Files\Java\jdk1.8.0_101\bin

I changed those around constantly, but all my old code still runs, and some new classes still run. But for some reason some new classes will generate the error:

Error: Could not find or load main class.

How do I solve this error?

Pang
  • 9,564
  • 146
  • 81
  • 122
DavidBoyd
  • 3
  • 2
  • 6
  • What is exact command that you run? What is your working directory and where are your class files? – Thilo Mar 10 '17 at 01:37
  • 1
    Your classpath should be where **your** class files are. Adding both the JDK and JRE to your PATH is unnecessary. Finally, **what** are you trying to run? – Elliott Frisch Mar 10 '17 at 01:38
  • I'm just running class files, like the ones above, in eclipse. There isn't a particular file I need to run, I'm just trying to figure out why some run and others generate the error. – DavidBoyd Mar 10 '17 at 01:42
  • I changed the classpath to my workspace folder that has all the project folders. That's the closest I can get to being the working directory to my class files. I rebooted eclipse and am still getting the error on the parserpractice class, and HelloWorld still works. – DavidBoyd Mar 10 '17 at 01:45

3 Answers3

0

Can you change your path and classpath like this

Path variable name: %ProgramFiles%\Java\jdk1.8.0_101\bin;%ProgramFiles%\Java\jre1.8.0_101\bin; ClassPath variable name: %ProgramFiles%\Java\jdk1.8.0_101\bin

Vinod Krishnan
  • 141
  • 2
  • 13
0

I used eclipse on my laptop and it worked fine. I think the issue has something to do with how old my PC is. It's ancient. I'm building a new one in the next couple months.

So, I'm closing this question as I tried everything possible, and at this point I think it's some esoteric problem that isn't even worth trying to figure out. I might try and re-install eclipse, and see if that fixes it, but since I'm getting a new PC I might not even bother.

Thanks for your help.

DavidBoyd
  • 3
  • 2
  • 6
-1

You can check your path for referenced libraries. Go to referenced libraries >Build path > configure build path and check whether all the paths are correct or not.