In my project there are some modules.
I want to use func from another module in my project.
I tried some ways to do this.
When I wrote:
studentManager studentMng = new studentManager();
studentMng.createStudent(student);
in line 1, I can see that studentMng is null (in the debugger).
So I get nullPointerException.
All this code located under main func (public static void main(String[] args)
then if I use another option I get conflict about static.
What I have to do?
Thanks.
Related
Currently trying to use Junit to create some concurrency tests to run in Jmeter
My current project Structure looks like this
From RasterTest.java, I'm trying to call a method in CommonMethods.java and a method in SetUp.java.
When I run this as a JUnit Test in eclipse, the methods in CommonMethods and SetUp are called and everything works fine. When I export this to a JAR and run the same in Jmeter, I get an error given below (getProperty is a method inside SetUp )
Trace -- java.lang.NoSuchMethodError: utils.SetUp.getProperty
I couldn't find any resources, hence i thought this maybe due to the methods being static, but i tried accessing the method by creating an object too. That Didn't help, got the same error.
Attaching the class CommonMethods for reference :
public class CommonMethods {
public String getProperty (String key) {
// Some code
}
public void setUrl() {
System.out.println("Hello world");
}
}
Calling it as :
CommonMethods cm = new CommonMethods();
System.out.println(cm.getProperty("URL"));
cm.setUrl();
I don't understand why Jmeter throws this error and how do i get around it? Thanks!
Hope you are using jpgc-perfmon-2.1. If not zip that into jmeter and then remove plugin cmn jar file from lib and update jmeter-plugins-cmn-jmeter.jar file with the latest version.
Seems like its kind of configuration issue.
How to call JAR CLASS with CMD
I am a newcomer to java.
This is my JAR file
https://drive.google.com/file/d/16bL0n4KS9IP75tDJhhbeNLeiS3boX3iP/view?usp=sharing
I want to use CMD to call the CLASS inside JAR.
I tried to call getHardware()
java -cp uhfrcom13_v1.9.jar com.handheld.uhfr.UHFRManager.getHardware
I got the error
The main method is not found, define the main method as: public static void main(String[] args) Otherwise the JavaFX application class must extend javafx. The application class must extend javafx.application.Application
Please master teach me how to call
In UHFRManager class you have to add public static void main(String[] args) - in this method you can call your getHardware() method. When running jar file, java is always looking for main method in your class.
Make the following changes and it will work.
Make sure to have a main method (public static void main (String [] args)) in your class where getHardware is a method, then call your getHardware method to work on from the main method [you should call the class from CMD and not the specific method!!].
Make sure to use the following command, in CMD, assuming your class is UHFRManager and getHardware is a method inside it,
java -cp "uhfrcom13_v1.9.jar" com.handheld.uhfr.UHFRManager
I hope it works.
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");
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
I'm using ASM Java library to generate a class X from scratch. Inside one of the static methods of this class I need to push a reference to X.class. Since there isn't yet a X.class I can't use visitLdcInsn. Is there a way to do it?
Well, it's possible (and I'm currently using it) to generate the following code (new X().getClass()), but I'm sure that's not the cleanest way to do it.
With generated code you usually don't need to push the class onto the stack. Anything you can do with a method call is usually available in byte code.
Say you have to call a method with a class, you can push it onto the stack whether it exists or not.
Something I use is the ASMifier. This is useful because you can start with a class which compiles and does what you want as a template and get it to dump all the code needed to recreate the class. This means you don't really need to write most of the code yourself.
public class Main {
public static void main(String... args) throws IOException {
ASMifierClassVisitor cv = new ASMifierClassVisitor(new PrintWriter(System.out));
ClassReader cr = new ClassReader("X");
cr.accept(cv, 0);
}
}
class X {
{
System.out.println("Inside class "+X.class);
}
}
prints
// lots of code
mv.visitLdcInsn(Type.getType("LX;"));
// more code.