Error running Java program in Eclipse form Github - java

So I am very new to using Github with Eclipse. When I import a project into eclipse by using the HTTPS clone URL and try to run it, it gives me the error:
Error: Could not find or load main class UserEnviorment.Main
The project is stored in:
Macintosh HD > Users > Kyle > git
but the Eclipse workspace is somewhere else. Would this cause problems?
Here is the class I am trying to run if that helps any
package UserEnviorment;
import java.util.*;
public class Main
{
public static void main(String[] args) throws Exception
{
// Does stuff until user exits program.
}
}
I apologize if this is a stupid question, but any help is much appreciated!

Nevermind, I seem to have found a solution. If I delete the project in Eclipse but don't remove the files from my hard drive, I can then create a new Java project in Eclipse and uncheck the box "use default location" and navigate to where the Github project is stored.

Related

How to solve "Could not find or load main class.." in Eclipse workplace

I'm create chrome testing function in eclipse.
The program have no error. But wile executing the program it shows following error.
Error: Could not find or load main class CrossBrowserTesting.ChromeTesting
Caused by:
java.lang.ClassNotFoundException: CrossBrowserTesting.ChromeTesting
But I didn't have idea Why this error is appear. Because My code has no error.
I enclose my code as below,
package CrossBrowserTesting;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ChromeTesting {
public static void main(String[] args) {
WebDriver driver;
System.setProperty("webdriver.chrome.driver","\\selenium webdrivers\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.example.com");
driver.quit();
}
}
My file structure is
-- Foldername
-- src
-- CrossBrowserTesting
-- ChromeTesting
Clean the project, You can find clean... option in Project tab between Search and Run.
I have the same error, I have solved this problem by go to menu : Project>clean
and it works for me.
I also got a similar problem a few days ago, steps which I follow to resolve the issue
Right click on Project(a project that showing error)
Go to the build path section and then click on configure build project.
Now remove the JRE library.
Now click on add library and click on JRE system library.
Now click on Execution environment and then finish.
Hope the error is gone now, It happens because sometimes some JRE file missed.

IntelliJ Idea Completion Error

I am new to Idea IDE. After installed it for a few days, I was fascinated with its outstanding features.
However, while I was actually writing code yesterday. I discovered that when the auto completion popped out, it showed nothing about the method of the object , merely some basic template say sync() var() ..... etc.
I have tried to setup the environment (Check the power save ...etc), but those previous solution seems to be for those whose auto-completion is turned off . Is there a way to fix it ?
THANKS IN ADVANCE!!
When you have create your project, you might not have marked it as a Java project and provide a SDK.
You can check it in File -> Project Settings -> Project -> Project SDK.
If not, you can download the JDK on the Oracle site http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
You can also try to write a
public static void main(String... args) {
System.out.println("It works !");
}
and write click on the "main" word. You should have a "Run 'Main'" option.

Error in Eclipse -Could not find the main class(Running NFC Example)

I am trying to run an example which I pulled out from open-nfc.org.
I have followed all the instructions provided by this site, however when I am trying to run the program I am getting the following error
Error: Could not find or load main class Processing
I have attached the program
package NFC;
import org.opennfc.*;
public class FinalNFC {
public static void main(String[] args) {
NfcManager mgt = NfcManager.getInstance(null);
System.out.println(mgt.getProperty("open_nfc.version"));
try {
System.out.println(mgt.getProperty("nfcc.firmware_version"));
} finally {
try {
mgt.stop();
} catch(NfcException e) {
System.out.println("Error :" + e.getMessage());
}
}
}
}
I have tried searching for this problem in stack overflow but nothing is seemed to solve this issue !
I am new to the Eclipse, so step by step Solution is really appreciated.
Else can anyone give me some site so that i can code in nfc using java ?
Firstly, Try running your program through native command line process, though your program syntactically seems ok but still that will give an idea about APIs as i could guess you're naive for eclipse.
Secondly, i had faced similar problem before what worked for me was re-configuring JVM.
Thirdly, What kind of project you have made in eclipse. For example if you are running Dynamic Web Project i.e. if you're running complete project itself then error you are getting is obvious. Then try running only the file by right clicking on it and select run file.
Hope this helps.
Firstly right click on your eclipse project and select "run as - Java Application". Then it will start searching main class and it will show you lots of classes then in search window type "FinalNFC" then select that class and run it.

java.lang.ClassNotFoundException: com.example.Main in intelliJ and Maven build

Here's my code which sets up the server using Jersey+ Grizzly combination from here. I haven't modified anything. also, all my files in the package com.example.
package com.example;
A rough skeleton of the Main.java which has the main(String[] args) is:
public class Main {
public static void main(String[] args) throws IOException {
code;
}
}
Also, there are other .java classes which don;t have main method. The project is being built by Maven and I use IntelliJ. The two execution profiles I have are:
Working directory : Z:/IdeaProjects/com.example with command line arguements:
clean test and exec:java
I understand that i need to run my Main but I don't know how to do it via Maven+IntelliJ. Can someone please help me?
I'm not sure exactly what you are trying to do, but I usually just right click on the main method and then click on the Run option. If you haven't downloaded all your dependencies, then go ahead and click on the Maven Projects tab, on the right side of the screen and run the compile stage to download all of your dependencies.
If you attached the error message you are getting that might help us narrow down the issue you are having.
You need a directory per package component. The path should be com/example/Main, not com.example/Main.

JUnit error: Could not find or load main class (RemoteTestRunner)

I've downloaded Junit version 4.10 and loaded the jar via the build path but I seem to get this error message when running a Junit test in Eclipse:
Error: Could not find or load main class org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
My Test class is the following:
import org.junit.*;
import static org.junit.Assert.assertEquals;
public class InternetConnectTest {
#Test
public void testConnectMethod(){
InternetConnect net = new InternetConnect("www.google.com");
assertEquals("Result", "www.google.com", net.url);
}
}
I came across this after I updated java versions: "junit: could not load main class 1.1". Go into the eclipse external tools configurations, open the entry for the ant file you are running, then go to the JRE tab, and select "Separate JRE", also making sure your new jre is correctly listed in the Installed JREs...for me, this took care of it.
This is an Eclipse error message. It seems your installation is corrupted. Try using a fresh installation of Eclipse.
Before trying a fresh install i just restarted eclipse and it did the trick.
I just had the same problem.
I relaunch Eclipse with the "-clean" option, and it did the trick too.
Edit:
How to run eclipse in clean mode? and what happens if we do so?

Categories

Resources