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,820 points
4,717 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
2,578 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, 2019 in Java by Jim
• 810 points
2,281 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,140 points
4,820 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, 2019 in Java by FooBayo
• 120 points

edited Jun 19, 2019 by FooBayo 2,931 views
+1 vote
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,620 points
1,319 views
+1 vote
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,290 points
1,178 views
+1 vote
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,680 points
3,734 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
1,996 views
+9 votes
16 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,620 points
463,696 views
0 votes
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP