Java错误无法找到或加载主类包 [英] Java error Could not find or load main class package

查看:201
本文介绍了Java错误无法找到或加载主类包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从eclips运行这个代码将会给出错误print:

When I run this code from eclips it will give the error print:

package Chapter08_JavaIOFundamentals;
import java.io.Console;

public class Echo {
     public static void main(String []args) {
          Console console = System.console();
          if(console == null) {
              System.err.println("Cannot retrive console object - are you running your application from an IDE? Exiting the application ... ");
          ystem.exit(-1); }
     console.printf(console.readLine());
     }
 }

但是当我试图从命令行运行它像这样。

But when i try to run it from a command line like this.

javac Echo.java //(this will gives no errors)
java Echo

它会给出一个错误:
错误:找不到或加载主类Echo。
其他程序就像Hello World没有问题。
这里有什么问题?

it will give a error: Error: Could not find or load main class Echo. Other programma's like Hello World give no problem. What is the problem here?

推荐答案

你必须调用 java -cp。 Chapter08_JavaIOFundamentals.Echo 的父亲方向

You have to call java -cp . Chapter08_JavaIOFundamentals.Echo from the parent directionry of Chapter08_JavaIOFundamentals

这篇关于Java错误无法找到或加载主类包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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