类路径似乎正确,但JVM仍然找不到或加载主类 [英] Classpath seems correct but JVM still could not find or load main class

查看:382
本文介绍了类路径似乎正确,但JVM仍然找不到或加载主类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对编程和java比较陌生,我试图学习如何从命令行创建一个用户定义的包。我得到以下:错误:找不到或加载主类TestPhone 。我已查看有关此类错误的帖子,包括评论效果好的帖子, java ,期望类的完全限定名, mobile.TestPhone ../ mobile 目录不需要在类路径中。


I am relatively new to programming and java and am trying to learn how to create a user-defined package from the command-line. I get the following: Error: Could not find or load main class TestPhone. I've reviewed posts on this type of error including the well-commented post here. The post lists 4 steps that the JVM goes through to run a java program:

  1. Search for the compiled version of the class.
  2. Load the class.
  3. Check that the class has a main method with signature static void main(String[]).
  4. Call that method passing it the command line arguments as a String[].

Apparently, my JVM can't find my TestPhone.class for some reason I am yet to figure out. Here's my directory structure:

My classpath is set as follows:

My classes contain simple codes from Mala Gupta to test accessibility of class variables:

package mobile;
class Phone {
    static boolean softKeyboard = true;
}


package mobile;
class TestPhone {
    public static void main (String[] args) {
        Phone.softKeyboard = false;

        Phone p1 = new Phone();
        Phone p2 = new Phone();

        System.out.println(p1.softKeyboard);
        System.out.println(p2.softKeyboard);

        p1.softKeyboard = true;

        System.out.println(p1.softKeyboard);
        System.out.println(p2.softKeyboard);
    }
}

Any idea why it doesn't find my classes? Many thanks.

System specs: Java version 1.8.0 Javac 1.8.0 Win 7 on 32-bit OS

解决方案

The java application launcher, java, expects the fully qualified name of the class, mobile.TestPhone. The ../mobile directory need not be in the classpath.

这篇关于类路径似乎正确,但JVM仍然找不到或加载主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆