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");
Related
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 am referencing PlayerUtil.getMovementSpeed(player); in my Speed class, and in my PlayerUtil class, I have the method defined as:
public static double getMovementSpeed(Player player) {
//my code here
}
But whenever the getMovementSpeed method is referenced in my other classes, it throws this error:
java.lang.NoSuchMethodError: net.Swedz.util.PlayerUtil.getMovementSpeed(Lorg/bukkit/entity/Player;)D
I thought it may be that Eclipse was exporting incorrectly, but I rebooted it and tried again with no avail.
EDIT: I did try decompiling the exported jar, and the public static double getMovementSpeed(Player player) method does exist in the exported jar.
EDIT: My friend is also having a similar issue, and is using IntelliJ, so Eclipse is not the issue.
EDIT: Class definition for PlayerUtil:
package net.Swedz.util;
public class PlayerUtil implements Listener {
//getMovementSpeed is defined in here
}
Class definition for Speed:
package net.Swedz.hack.detect.move;
public class Speed implements Hack, Listener {
//my detection methods and method containing PlayerUtil.getMovementSpeed(player);
}
SOLUTION: I found on my own that I had classes conflicting between two plugins on my server. I had one jar with net.Swedz.util.PlayerUtil and another with net.Swedz.util.PlayerUtil both with different contents. I added my project name in all lower case after the net.Swedz and it seems to have fixed it!
Thanks!
This is a very simple to troubleshoot.
you have used that method and you were able to compile that class which uses this method.
so that means at compile time it reefers the class PlayerUtil which has this method.
But runtime class loader has loaded the class PlayerUtil which doesn't contain this method.
now what you have to do is just find out where that class has been loaded from (at run time)
if you can recreate the problem while it is running using eclipse/IDEA follow these steps.
(if it runs in in application server or standalone application, then start the application server or application with debug enabled.and you can do remote debug from your IDE).
put a break-point where exception was thrown (where you call this method).
start to debug , it will hit the break-point.
then evaluate this expression PlayerUtil.class.getResource("PlayerUtil.class")
4.you can find the path where the class was loaded from.
now you have two options , decompile the class and check whether that method is these (same return type, same name , same args).
or in debug , you can evaluate PlayerUtil.class.getDeclaredMethods() to find out.
So you can solve the problem by rectifying the class path entries if it was loaded from a wrong place.
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
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
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).