MasterDevX / Termux-Java

Install Java (Open-JDK-8) in Termux without root!
381 stars 82 forks source link

Could not find or load main class #21

Open kparsh19 opened 4 years ago

kparsh19 commented 4 years ago

Hi there. I had installed the package using your script. But when i issue the java command to run my program it throws the error "Could not find or load main class". I don't know how to solve this issue in termux and also -jshell command is not working. Can you help?

GuzioMG commented 4 years ago

I have no clue, what's causing the lack of -jshell, but "Could not find or load main class" is a problem with your application, not Java*. It means, that the file you're trying to run does not have a main() method. The only solution I can see here is:

*However, if you're still not sure, you can always try running a different app, that you're sure, it works. Minecraft server is running fine (although it melts your phone). I checked.

kparsh19 commented 4 years ago

Well, I will give answer to your points in the same way 1) I think this is the main reason behind this. I have seen some videos about this same issue coming in windows, they have solved it by making a new environment variable 2) It is impossible (I hope) because it's termux 3) There is nothing related to .jar/-jar because it's one of the simplest program I have written using an editor with .java extension and I just want to compile/run it on termux May be it is due to absence of -jshell or may be there's something wrong in this package. While compiling the program using javac (.java) it compiles fine and also I had seen that .class file is also generated but this error occurs when I try to run it using java command. I have checked the path.

GuzioMG commented 4 years ago

Well... It's probably exactly what you just did and I'm asking this question for no reason, but: Are you sure that (since you're running a .class file) you're using java Program not java Program.class? I just checked and java Program.class returns Error: Could not find or load main class Program.class, while the other one works. Also, you must be in the same folder.

kparsh19 commented 4 years ago

Yeah, I have used java_program and not java_program.class with java command because I know that latter will create this error. But the unfortunate is the same error with java java_program command

GuzioMG commented 4 years ago

:-/ Well, I have no clue then.

But could you please try running a .jar file, just to make sure it's really not working? Maybe there's an issue with .class files on your phone. For... some reason 🤔?

johnmalib commented 1 year ago

According to the error message ("Could not find or load main class"), there are two categories of problems:

The Main class could not be found when there is a typo or wrong syntax in the fully qualified class name or it does not exist in the provided classpath.

The Main class could not be loaded when the class cannot be initiated. Typically the main class extends another class and that class does not exist in the provided classpath.

For example:

public class YourMain extends org.apache.camel.spring.Main

If camel-spring is not included, this error will be reported.

Other reasons to occur this error is :