I have an Interface class checked out from an svn project, and created an Interface_Tester class to preview the interface. However, when I try to run it in Eclipse I get the following error:
Error: Could not find or load main class Interface_Tester
Here is the code from the interface_tester class -
public class Interface_Tester {
public static void main(String[] args){
Interface test = new Interface();
}
}
I have seen a similar question asked on here but did not understand the answer. I need a step-by-step guide to the solution as I am a beginner. Thank you
UPDATE:
I tried running the Interface class itself and had the same error... All classes are being shown in the project explorer on the left so why is eclipse unable to locate any of them?
On the left side of Eclipse you have a project view. Try right-clicking your Interface_Tester from there and in a dropdown choose run. May be you you are trying to run something else
Related
I have just started learning Java using an online course.
When I create a new project with IntelliJ, I don't have the Main class in the src folder. However, the instructor is saying IntelliJ should create the class "Main" by default.
HOW I SHOULD HAVE IT:
-"Name of the project"
-Idea
-src
-"com.myname"
-Main (the Class)
HOW I HAVE IT:
-"Name of the project"
-Idea
-src (which contains nothing)
Therefore, I have to create manually the class "Main" by clicking on "src" and creating a class named "Main" with this code inside:
Public class Main {
public static void main(String[] args) {
}
}
MY QUESTION: how can I set IntelliJ to automatically create the main class every-time a new create a new project?
Many thanks for your help.
Create the project from template:
Command Line App will add a class with the empty main method.
I am learning how to use packages in Java, but I am running into trouble when trying to implement them. I have a simple class called Main which appears as follows:
public class Main
{
public static void main(String[]args)
{
System.out.println("Package Test...");
}
}
The directory of this class is: C:\Users\MyComputer\Desktop\Packages\Main.java
When I compile this class, I run into no trouble. However, when I add "package com.example.mypackage;" to the top of the .java file, compile the program, and try to run the program, I receive the following error: "Error: Could not find or load main class Main"
What can I do to solve this problem?
If the path of your class is C:\Users\MyComputer\Desktop\Packages\Main.java then your class is not in a package. In this instance "Packages" is your project folder, and it only contains the one java class.
If you want package com.example.mypackage; to work, then your path needs to be:
C:\Users\MyComputer\Desktop\Packages\com\example\mypackage\Main.java
I use soot for instrumenting a java program. I know for adding invocation to specific class in soot, we must set "Soot class-path" to the directory contains that class, .class file. So I do this in main method of main class. I bring the snippet of code bellow
public class Main {
public static void main(String[] args) {
Scene.v().setSootClassPath("/home/j/IdeaProjects/Test_1/classes:/home/j/IdeaProjects/Test_1/libs/rt.jar:home/j/IdeaProjects/Test_1/libs/jce.jar");
PackManager.v().getPack("jtp").add(new Transform("jtp.RetIns", new ExIns()));
....
But when I want to use "Insop" class which resides in classes folder, by following code in Exins method:
static SootClass Ins;
static
{
Ins= Scene.v().loadClassAndSupport("Insop");
}
I get the error
Caused by: java.lang.RuntimeException: couldn't find class: Insop (is your soot-class-path set properly?)
I should mention that I use ubuntu 14.4 32 bit and I run the code on intellij.
I can not find what is my mistake. could you please help me.
I finally find the problem. I don't know why, but I should set "soot class-path" with relative path. For my project for example it should set as follow:
Scene.v().setSootClassPath("classes:libs/rt.jar:libs/jce.jar");
I just added some code to a project and suddenly I get these errors. The class in question does have a main method and the other class ClientLauncher in the client package exists. I checked and the classes have the correct package listed in them. Any suggestions on what I should check? Thanks.
Error: Could not find or load main class client.ClientLauncher
selection does not contain a main type
I'm not sure if this is what was going on, because I had deleted the last project and started over. But I just got a similar error and thought I'd post this in case it helps someone. In the process of doing a similar project, I forgot to include "String args[]" in the main method definition and only had"
public static void main(). This gave a similar "does not have main method". The moment I added the above and had:
public static void main(Strings args[]);
then the error went away and the code ran correctly.
When I want to run my java code, I have this problem :
Exeption in thread "main" java.lang.ArrayIndexOutOfBoundsException:0
at com.ibm.icu.text.BreakDictionary.main(BreakDictionary.java:44)
i can't run my code... It's simple
public class main{
public static void main(String[] args){
System.out.print("Hi");
}
}
WTF is com.ibm.icu.text.BreakDictionary?
Make sure of the class whose main you are running. I suspect you're not running your class. Your java command should look like this:
java -cp somepath com.mycompany.mypackage.MyClass
Better yet, use an IDE like eclipse that make it easy to run a class
Also, rename your class from main to MyClass - anything with a leading capital letter - it's good coding style
Exeption in thread "main" java.lang.ArrayIndexOutOfBoundsException:0
at com.ibm.icu.text.BreakDictionary.main(BreakDictionary.java:44)
This exception says that you are running the main method in a class named BreakDictionary. In your sample code the class is called main.
You can solve this in eclipse by right-clicking your class and select run as and then java application. This will ensure that you are using your main class as the entry point and not BreakDictionary (which seems to either be on your classpath or you are simply not running the correct project in eclipse).