Could not find or load main class main using Android Studio - java

I'm working on learning how to code games in Java. Since Android studio isn't supporting eclipse it just made sense to use the IDE I'm already using to write my Java programs. I had to do some digging but I figured out how to make that work.
My issue is that I can run the programs while in the IDE but when I try to run the program from the command line, even something as simple as "Hello, World" I get this error.
Could not find or load main class main
Now this odd because the director contains both a main.class and a main.java plus the program does compile and run when run from android studio itself. I would like to be able to resolve this to run my programs at the command line.

Related

Error while running a program on java on visual studio code

This is the porgram which I am running on visual studio code
When I run the program I am getting this error box
After getting the error box, it is showing this page.
What shall be done in this for the program to run on VS Code?
There should be multiple java files inside the folder you are currently opening in vscode and you are running one of them. There is a bug in another java script that causes a compilation error when you run the current file.
It doesn't matter, you just need to click on Proceed in the popup, which will continue to run the current code. As long as your current code has no errors, the program will run successfully and output the result.
Another way is to install Code Runner and then use the Run Code option it brings to run the code. This way it will only compile and run the current file, and will not bring compile errors.
But be aware that Code Runner may have errors when your file structure is complex.

How to work with NetBeans IDE 8.2 on Windows 7 64-bit with JDK

I've been having trouble using NetBeans IDE 8.2 with JDK on Windows 7 64-bit. NetBeans can compile code, but doesn't run it. I've downloaded all of the necessary files and programs and even consulted with a computer programming teacher, but I haven't been able to work around this issue. The URL displays an image that shows what I get back after attempting to run a code.
https://i.stack.imgur.com/RsEvx.png
I appreciate any help I can get.
Thanks,
--Sam
JavaApplication1.java is still set as your main class.
To change your main class, go into Project Properties -> Run and change "Main Class" to TestClass.java.
Essentially, the compiler is still running whatever main function is found in JavaApplication1.java.
#notyou Also mentioned how you can right click a file and run it directly, instead of changing the project settings. I used to use this but it slipped me! This is super useful.
I'm pretty sure this question has some answers for you.

Problems compiling and running Java in Notepad++

I recently downloaded a portable edition of Notepad++ and copied Java files in order to be able to use it for java development on the go. I got the plugins I needed, but can't get the code to compile or run. This is the code I have for the script to run and compile the java code:
cd "$(CURRENT_DIRECTORY)"
"F:\Java\jdk1.7.0_11\bin\javac.exe" $(FILE_NAME)
"F:\Java\jdk1.7.0_11\bin\java.exe" $(NAME_PART)
I'm getting an error that says
CreateProcess() failed with error code 2: The system cannot find the
file specified.
I've tried multiple solutions and tinkered with the code to try and solve it, but nothing has worked. What am I doing wrong?

How to apply changes to an Android Cordova App Java source file using PhoneGap CLI?

I need to insert some native functionality into my Android app built with PhoneGap/Cordova (v4.2). Specifically, I want to override the onWindowFocusChanged() of the CordovaActivity class in my app, and I don't think I can do this through a plugin. (I'm building a kiosk application and I want to collapse the status bar as soon as it is opened. The code works in another app (which is native) and I'm trying to do the same here)
I've already edited the CordovaApp.java file located in platform/android/src/[package-name-inverse-URI], rebuilt the project using the CLI command phonegap build android to generate an APK, but unfortunately, I was not successful.
Oddly enough, even when I purposely type erroneous/invalid java code into that file and rebuild, no error messages are displayed, which led me to believe that this file is not compiled at all on the build process.
Is there any way that I could edit the main activity file and compile it into the APK?
I figured it out. When erroneous code is added to the main activity java file, cordova actually tries to compile it, obviously fails and silently exits. To phonegap, which runs over Cordova in the NPM module, the build process is successful.
To actually see the error output of the Java compiler, you'd need to add the verbose/debug flag, calling:
phonegap build android -d
With that output, I've managed to see what was wrong with the code and fix it.

Eclipse Won't Compile/Run Code Pasted Into the Source Folder, Only Ant Build Available

I've tried looking at many other pages and nothing has seemed to solve the problem. I have a program that was written on another computer, and I would like to work on it on the computer I am currently using. I have a bunch of .java files from the other computer and I've put them into the source folder of a Java project I've just created on the computer I'm using, as I'm trying to reproduce the project on the computer I'm currently using. However when I try to run the code it only lets me use ant build. How can I get it to run normally? I do have a main method and I'm trying to run it from that main method.
Yo you may have to make a new project then copy and paste the code in to the package explorer.
Here's a video I found that may help you out. Hit me back if this helps.
https://www.youtube.com/watch?v=bOGxozUTm3Q

Categories