javac: file not found: polymorphism.music.Music.java or Error: Could not find or load main class pol

本文详细解析了Java命令的基本格式,包括如何指定最大内存、加载并运行特定类的方法,以及如何传递命令行参数。同时,针对常见的编译和运行时错误,如文件未找到、主类找不到等问题,提供了具体的解决步骤和建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

An example of what a java command should look like:

    java -Xmx100m com.acme.example.ListUsers fred joe bert

The above is going to cause the java command to do the following:

  1. Search for the compiled version of the com.acme.example.ListUsers class.
  2. Load the class.
  3. Check that the class has a main method with signaturereturn type and modifiers given by public static void main(String[]). (Note, the method argument's name is NOT part of the signature.)
  4. Call that method passing it the command line arguments ("fred", "joe", "bert") as a String[].

Q1. javac: file not found: polymorphism.music.Music.java 

A1: instead use

$ javac polymorphism/music/Music.java

also use absolute classpath, for example,

javac ~/user/polymorphism/music/Music.java

Q2: Error: Could not find or load main class polymorphism.music.Music

A1: be sure already has Music.class, then use

$ java polymorphism.music.Music

or 

java polymorphism/music/Music

If you want use javac/java in current directory, you need modify source code. Remove package sentences and some comments in exmaples code.

refereces:

1. https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值