Error: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2

+1 vote

I wrote a simple code for finding whether a number is even or odd. Here is the code :

import java.util.*;
public class EvenOdd {
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a number");
        int num = in.nextInt();
        if (num % 2 == 0)
            System.out.println(num+" is even");
        System.out.println(num+" is odd");
    }
}

Output:- I am getting the output but there is an error aswell

Enter a number
2
2 is even
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [util.c:840]
Nov 21, 2018 in Java by Jino
• 5,560 points
1,058 views

1 answer to this question.

+1 vote

Hello @Jino,

It is just a JVM bug its harmless and wont effect your code. You can use System.exit(0) at the end to avoid it.

The code you have written is not correct. You forgot to use else. Java doesn't follow indentation like python does. When you will input an even number it will print it as both odd and even.

import java.util.*;
public class EvenOdd {
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a number");
        int num = in.nextInt();
        if (num % 2 == 0)
            System.out.println(num+" is even");
        else
            System.out.println(num+" is odd");
    }
}
answered Nov 21, 2018 by Nabarupa

Related Questions In Java

0 votes
1 answer

How to fix the error failed to load the JNI shared Library?

You need these three things : 64-bit OS 64-bit ...READ MORE

answered Apr 19, 2018 in Java by sophia
• 1,400 points
638 views
+1 vote
2 answers

Is there a code to find 64-bit JVM or 32-bit JVM (from within a program)?

Do I need to understand the difference ...READ MORE

answered Jun 11 in Java by Jim
• 810 points
279 views
0 votes
1 answer

Unable to find valid certification path to requested target - error even after cert imported

Unfortunately - it could be many things ...READ MORE

answered Nov 27, 2018 in Java by Daisy
• 8,050 points
1,314 views
0 votes
0 answers

Sending request using json object return 404 error code

I am getting mad with this code ...READ MORE

Jun 19 in Java by FooBayo
• 120 points

edited Jun 19 by FooBayo 100 views
0 votes
1 answer

Are arrays equivalent to objects in Java ?

Yes; the Java Language Specification writes: In the Java ...READ MORE

answered May 10, 2018 in Java by Rishabh
• 3,540 points
77 views
0 votes
1 answer

Remove objects from an array in Java?

We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,280 points
65 views
0 votes
1 answer

Performance difference of if/else vs switch statement in Java

The thing you are worried about is ...READ MORE

answered Jul 26, 2018 in Java by geek.erkami
• 2,640 points
524 views
+1 vote
2 answers

How to use try & catch block in Java?

Hey @Jino, Using try catch block for your ...READ MORE

answered Dec 21, 2018 in Java by Nabarupa
56 views
+9 votes
11 answers

Unable to resolve this error: "javac is not recognized as an internal or external command"

Check your javac path on Windows using Windows Explorer C:\Program Files\Java\jdk1.7.0_02\bin and ...READ MORE

answered May 23, 2018 in Java by Rishabh
• 3,540 points
43,451 views
0 votes
2 answers

How to round a double to 2 decimal places?

double value = 200.3456; System.out.printf("Value: %.2f", value); You can ...READ MORE

answered Dec 11, 2018 in Java by Sushmita
• 6,880 points
753 views