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.
Related
lets say you have following classes:
public class A {
public void run() {
synchronized(B.class) {
System.out.println("A: here");
}
}
}
public class B {
public void run() {
synchronized(B.class) {
System.out.println("B: here");
}
}
}
So the code inside the sync block for obj a and obj b is synced, if its running on the same jvm.
I want to test the sync, so i have a JUnit Testcase for Class A and Class B.
I run the two Testcases over eclipse via the Eclipse Menu DebugAs->JUnitTest.
The result is, that there is no synchronization. Is this because Eclipse creates a new JVM for every started JUnit Testcase ?
If yes, is there a way to test the sync ?
Thank you already
The problem was running the Testcases seperatley.
With this it worked:
#Test
public void test() {
Class[] cls = {A.class,B.class};
// Parallel among classes
JUnitCore.runClasses(ParallelComputer.classes(), cls);
}
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!
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 want to run .exe application with two parameters.Its VB .exe application its need two parameters to execute ? I tried with create .cmd file to execute .exe application, its working good.
Please see the which code running .cmd file.
start xx.exe ./aa.txt,2012
Same procedure following in java, but giving error...
Please find the below small java program.
public class Invoke
{
public static void main(String as[])
Runtime r=Runtime.getRuntime();
Processp=null;
try
{
String s="...complie.exe";
String d="...de.txt";
String l="...foldername";
p=r.exec(s,d,l);
}
catch(Exception e){
}
Please advise...
Here is an example how to start jEdit program and some txt file from Java:
import java.io.IOException;
public class Invoke {
public static void main(String[] args) {
try {
Runtime.getRuntime().exec("C:/Program Files/jEdit/jedit.exe");
Runtime.getRuntime().exec("notepad C:/Program Files/TechSmith/Camtasia Studio 7/TSCCinst.txt");
} catch (IOException e) {
e.printStackTrace();
}
}
}
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.