Dear StackOverflow Community,
I need your help with the compilation of two Java files per JDB`s Command Line Debugger. Unfortunately, I'm not able to debug two Java files.
I know how to run, compile and set Breakpoints with just one Java-File. Everything is great and works fine.
However, I would like to compile two files.
For example one Java-File DoSomething with a simple Method:
public class DoSomething {
int count = 0;
public int getInt() {
int i = 0;
while( i < 10 ) {
count++;
i++;
}
return count;
}
}
And the Main Class:
public class Main {
public static void main( String[] args ) {
DoSomething ds = new DoSomething();
ds.getInt();
}
}
If I start by the command line the Java compiler I can pass a breakpoint.
For example:
jdb Main DoSomething
Initializing jdb ...
stop in DoSomething.getInt
Deferring breakpoint DoSomething.getInt.
It will be set after the class is loaded.
run Main
run Main
And here is the output:
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
VM Started: Error: Master class TestMain could not be found or loaded
The application exited
What am I wrong or where is my error?
Thank you very much!
Related
class one
{
void call()
{
System.out.println(" A method");
}
}
class two extends one
{
void call()
{
System.out.println(" B method");
}
}
public class Dispatch{
public static void main(String[] args) {
one a=new one();
two b=new two();
one r;
r=a;
r.call();
r=b;
r.call();
}
}
IDE used: VSCode
This was an attempt to implement runtime polymorphism. I used the same example used in "Java -the complete reference -Herbert Schildt", but it shows an error:
"Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from two to one".
Your example compiles and runs without errors on my machine (using Eclipse).
Some ideas: Maybe your IDE is set to recompile only on manual request (instead of the typical default continuous building). Or maybe your IDE has some weird compiler warning settings configured.
Simple question here. Here is my Java file:
public class Test {
public static void main(String []args) {
System.out.println("It ran!");
}
void a() {
qweifjew;
}
}
When I press "Run" on VS Code, it says build failed do you want to continue? Makes sense since I have compile-time errors. But when I press continue, it is still able to run and display "It ran!". How come?
For more information on the run command:
C:\Users\jeffe\coding-tutorials\learning-jest> cd c:\Users\jeffe\coding-tutorials\learning-jest && c:\Users\jeffe\.vscode\extensions\vscjava.vscode-java-debug-0.27.1\scripts\launcher.bat "C:\Program Files\Java\jdk-11.0.2\bin\java.exe" -Dfile.encoding=UTF-8 -cp C:\Users\jeffe\AppData\Roaming\Code\User\workspaceStorage\5e0a770d0910238b624ead6f98bca1ec\redhat.java\jdt_ws\learning-jest_f8aabfb2\bin Test
It ran!
This is the decompiled .class file of your code:
public class Test {
public Test() {
}
public static void main(String[] args) {
System.out.println("It ran!ddfseffe");
}
void a() {
throw new Error("Unresolved compilation problems: \n\tSyntax error, insert \"VariableDeclarators\" to complete LocalVariableDeclaration\n\tqweifjew cannot be resolved\n");
}
}
You have Auto Save ON in VS code ?
It's able to run a previous successful build to give you an output.
I want to profile my test application started by IntelliJ. For profiling I useVisualVm.
I started the java tool with the parameter -J-Dorg.netbeans.profiler.separateConsole=true.
I started the application with the VM parameter -Xverify:none, otherwise VisualVM throws an error if I start profiling (Redefinition failed with error 62)
I want to profile my application before any important code has beed executed, so I tried to set a break point and start profiling in VisualVM. The problem is that VisualVm doesn't respond to any interaction while I'm waiting at my break point. Do I miss something?
In normal execution (without debugging) my program waits for input, so I can profile it without debugging. But what if a program doesn't has such "waiting points"?
My test application looks like that:
package my.visualvm.example;
import java.util.Scanner;
public class MainClass {
public static void main(String[] args) {
System.out.println("Starting Application: " + MainClass.class.getSimpleName());
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
double value = scanner.nextDouble();
if (value == 0d) {
break;
}
System.out.println(Powa.powaPowa(value));
}
System.out.println("Stopping Application: " + MainClass.class.getSimpleName());
}
}
Other class:
package my.visualvm.example;
final class Powa {
private Powa() {
}
static double powaPowa(double powa) {
return Math.pow(powa, 2);
}
}
Set the breakpoint to suspend the current thread only.
code:
public class JniTest {
static {
System.load("/usr/lib/libJniTest.so"); //It run have no exception and true
//System.loadLibrary("libJniTest");
}
public native void sayHello();
public static void main(String[] args) {
System.out.println(System.getProperties().getProperty("java.library.path"));
new JniTest().sayHello();
}
}
If use the comments code instead of "System.load("/usr/lib/libJniTest.so"), it will throw exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no libJniTest in java.library.path!
I have input
export LD_LIBRARY_PATH=/usr/lib in /etc/profile and set vm arguments:
-Djava.library.path=/usr/lib
Help me, Please!
Set VM arguments with :
-Djava.library.path="${workspace_loc}/project_name:${env_var:PATH}"
and make sure that .so should be in your project folder
I tried lot of options to fix this , but could not find a solution. I have created the header file and the dll too. Set the class path asd well. Javac command works fine. When I run this file, I get error: Could not find or load main class com.log.jni.example.HelloWorld. Could you please help me. Here is my file.
public class HelloWorld {
private native void print(String path);
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String path="C:\\Capture.pcap";
new HelloWorld().print(path);
}
static {
System.loadLibrary("HelloWorld");
}
}
Could it be that your static initializer is failing.
The following code:
public class Main
{
static
{
if (true)
throw new Error("Error is here");
}
public static void main(String... args)
{
System.out.println("I am running");
}
}
produces the output:
Exception in thread "main" java.lang.Error: Error is here
at Main.<clinit>(Main.java:22)
Could not find the main class: Main. Program will exit.
Are there any stack traces printed out before the 'Could not find main class' error? In this example, the class was found but failed to initialize because of the exception thrown in the static initializer. In your code, a likely suspect is that the System.loadLibrary() call fails with an UnsatisfiedLinkError.
The error "Could not find or load main class ..." occurs when the binary file is not built. Click on project, turn off automatic build. Then click on project and build all. Then turn on automatic build.