Jump to content

I want to run my program (java) on cmd, but an error occurred.

REDRIDINGHOODS
Go to solution Solved by AnirbanG007,
7 minutes ago, REDRIDINGHOODS said:

 

The java runtime that I downloaded is version Java SE Development Kit 15.0.2 (which is the recent one on java's website) and, it runs perfectly on notepad++. But the problem is why I can't execute my program on cmd.

IIRC, you need to install the JDK on some partition other than the C drive to compile and run programs from CMD. I ran into the same issue when I was in school. BlueJ would compile my programs fine, but CMD wouldn't. Installing the JDK in a partition other than C, helped me, and I could compile Java from CMD. I think it has something to do with access permissions from C drive or Program Files, not sure. Can you try this out?

 

PS: This was a long time ago, in 9th grade.

1 hour ago, REDRIDINGHOODS said:

I'm new on java programming but it occured a problem which is this:

 

image.thumb.png.4b3832580ae0ad1cbe95b781c7354c15.png

Did you do ?

import java.io.*;

IIRC, it is needed for SOPLN.

Edited by AnirbanG007

Attention is what makes life meaningful.

Also, please quote me for a reply. 🙂

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Sauron said:

Update the java runtime as the error says.

The java runtime that I downloaded is version Java SE Development Kit 15.0.2 (which is the recent one on java's website) and, it runs perfectly on notepad++. But the problem is why I can't execute my program on cmd.

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, AnirbanG007 said:

Did you do ?


import java.io.*;

IIRC, it is needed for SOPLN.

 

BTW, it also mentions a compatibility problem of the java runtime as mentioned by the other guy.

I change it to import java.io.*, still the error shows.

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, REDRIDINGHOODS said:

 

The java runtime that I downloaded is version Java SE Development Kit 15.0.2 (which is the recent one on java's website) and, it runs perfectly on notepad++. But the problem is why I can't execute my program on cmd.

IIRC, you need to install the JDK on some partition other than the C drive to compile and run programs from CMD. I ran into the same issue when I was in school. BlueJ would compile my programs fine, but CMD wouldn't. Installing the JDK in a partition other than C, helped me, and I could compile Java from CMD. I think it has something to do with access permissions from C drive or Program Files, not sure. Can you try this out?

 

PS: This was a long time ago, in 9th grade.

Attention is what makes life meaningful.

Also, please quote me for a reply. 🙂

Link to comment
Share on other sites

Link to post
Share on other sites

49 minutes ago, AnirbanG007 said:

IIRC, you need to install the JDK on some partition other than the C drive to compile and run programs from CMD. I ran into the same issue when I was in school. BlueJ would compile my programs fine, but CMD wouldn't. Installing the JDK in a partition other than C, helped me, and I could compile Java from CMD. I think it has something to do with access permissions from C drive or Program Files, not sure. Can you try this out?

 

PS: This was a long time ago, in 9th grade.

Thanks a lot.
I thought I needed to upgrade and update my OS (Windows 7).

Link to comment
Share on other sites

Link to post
Share on other sites

On 2/23/2021 at 3:07 PM, REDRIDINGHOODS said:

I mistyped it was "jre1.8.0_281", but it is the latest one on Java's websitet

Oracle has changed their licensing. You could try an OpenJDK version (e.g. from here: https://adoptopenjdk.net/) if you don't want to create an Oracle account.

 

Don't be confused by the name, there is a JRE version of OpenJDK.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

JDK should include runtime. Also, you don't need to 

import

anything for this particular program.

 

I would assume there is an older version of the JRE installed along with the new one that came with the JDK, and the system is defaulting to that one for running compiled Java bytecode, even though it is using the new JDK for compilation. 

 

You can check Programs and Features (under Control Panel) to see if there is an old version of the JRE installed. If there is, you can uninstall the old one (assuming you don't need it), or follow this StackExchange answer to specify which version of Java you wish to use.

 

Compiling Java programs via CMD should work just fine even if Java is installed on the C drive, the problem here is likely multiple versions of the JRE.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×