Don't run android application in eclipse - java

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).

Related

Receiving couldn't find class error even Setting Soot library classpath

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 am trying to overload the main method but I am getting following error in cmd

filename: mainoverloading.java
error: could not find or load main class mainoverloading
class simple{
public static void main(int a)
{
System.out.println(a);
}
public static void main(String args[])
{
System.out.println("Hi");
main(10);
}
}
Your class is named simple (not mainoverloading). Rename the class (or move the file "mainoverloading.java" to "simple.java").
When You compile the above given class using
javac mainoverloading.java
It is successfully compiled and a class file named simple.class is generated in your folder.
You can then run it by typing
java simple.
But this is actually not a good practice, as Elliott Frisch said rename your class into simple.java.
have a look For Windows- HelloWorld
For Linux - HelloWorld
Java allow us to use any name for file name, only when class is not public.
Its running nicely, because for eclipse main class it simple, its smart to identify that simple.class will be created.
If you are running from command line ,
class file created for your code is simple.class so JVM will be unable to find mainoverlading.class

Error: Could not find or load main class Mainclass

So I followed this site here and I don't think the part where I went wrong was the first part when it was talking about directories and stuff. I'm a real noob. Anyways, when I try to run the java program, it says Error: Could not find or load main class Mainclass. Any idea what's going on? I've tried installing the java jdk but that doesn't make a difference.
Details:
Here's a screenshot of what my page looks like.
Is there something I should change in my .build file? (I used the same one on the site). Thanks in advance.
You need to have a class called Main (or main) with a method like this one:
public static void main(String [] args){
//your main class code here
}
EDIT:
Try renaming your class to "Main" (no quotes).
Large Sized EDIT:
1.You need to make your class public class MainClass
2.You MUST have a package declaration!!!
3.You SHOULD probably rename your class to "Main" and your java file to "Main". Other than that, your programming is pretty solid!
Try below code:
sudo apt-get update
sudo apt-get install default-jdk
I cannot see your code but this is a sample code:
class greeting {
public static void main(String args[]) {
System.out.print("hi");
}
}
Happened to me recently, the Class file saved in your Cloud9 folder has a lower case letter, different from the Class name uppercase
Filename: Mainclass
ClassName: MainClass

Run two main class instances from one project in InteliJ IDEA?

Hello I have a problem that I want to run two distinct instances in one project. One is in Receiver module and second one in Sender. When I try to select Main class for another module in Run/Debug application I get following error. Is it even possible to run like this in idea ? I know this worked in Visual studio when we created new sollution. How about here ?
Do your main method has String[] args?
Remember that a class to be executable must have the following method:
public static void main(String[] args) throws Exception{
}
the throwing part is optional

Interface binding in Eclipse

I have the following code in Eclipse(Helios)/STS which runs and prints console output when doing a Run As> Java Application, in spite of obvious compilation issues
public interface ITest{
String func();
}
public static class Test implements ITest{
void printFunc(){
System.out.println("Inside Test Function");
}
}
public static void main(String[] args) {
Test test = new Test();
test.printFunc();
}
Can anyone pinpoint the reasoning behind this Eclipse functioning.
Note: Doing a javac externally obviously fails to compile.
Eclipse's Java compiler is designed to cope with flaky, non-compiling code. It will add whatever stuff is necessary to the code to get it to compile.
See this question What is the difference between javac and the Eclipse compiler?
It might have been that you have coded the class successfully before the errors. Eclipse auto-compiles your file while you are coding. Just then, you happen to have errors.. then you decide to run as Java Application, Eclipse will run the most recent compiled class.
I tried your code, implemented the necessary methods to remove the errors, then removed it again to put back the errors.. sure enough, it printed out "Inside Test Function". I also tried commenting out System.out.println("Inside Test Function"); and it still printed out.
In another try, I created another class, added your code, then run (without implementing the errors to avoid auto-compiling), then it printed out an error..
java.lang.NoSuchMethodError: main
Exception in thread "main"

Categories