I can't seem to get this program to work, and I am at a loss for why.
When I type java in to "run" (Using windows 7), I get the message
"Windows could not find Java".
I also have installed java and re-installed it to no avail. I have a feeling the directory is messed up (probably because I butchered it when I changed the boot drive to my SSD, and used my old hard drive as an internal storage drive).
your windows PATH for java is probably the problem.
when you type in java in to the run screen...windows locates the version of java defined by the path.
1) try typing java -version
if that doesn't work windows can't find the java installation.
2) try finding the java exciutable where you install java and trying running that directly
if that works its a path problem
Related
I had to install logisim ( a logic circuit editor) but java 5 or any newer edition was required to do so, while i also had downloaded jdk-13.0.2 in order to develop some java projects .I was given this link in order to download logisim:
http://www.cburch.com/logisim/download.html
Also, i downloaded java 8 from the following link:
https://java.com/en/download/manual.jsp?fbclid=IwAR2BoP89O7qYdbWc0Knk5tSSvymVDN-5XF9FdAKo-_OT4pLnnAG-dcxlC9M
Although logisim was succesfully installed to my computer , java stopped working. In adittion vscode reports that no jdk is installed and that classpath system variable points to 0 .
Anyway, I found out that my jdk is stored where it should be ,which means in programm files , while i realised that i had downloaded two more jdks !!! (I still dont know how these got in my computer ...).But this shouldn't really matter because the cmd programm used everytime before starting coding in java still sets the classpath and path system variables at the correct destinations .
The cmd code is the following:
set path="C:\Program Files\Java\jdk-13.0.2\bin"
set classpath=.;C:\Program Files\Java\jdk-13.0.2\lib\tools.jar
(My point is that it doesn't seem to be the above program's fault. )
I also can't find the java edition (java 8) I was supposed to have already to downloaded in order to install and operate logisim with the file explorer.
I really need to keep both logisim and vscode operanotional.
Does it mean that im able to code in java just by having jdk ? ( I wouldn't bother to download java 8 if it wasn't for logisim...).
Also whenever I try to compile a java file using cmd , I get the following error back:
An error has occurred while processing the shared archive file.
Mark mismatch while restoring from shared file.
Error occurred during initialization of VM
Unable to use shared archive.
Any ideas could be helpful.
A new path system variable must be created for the new JRE installation also (the one installed for Logisim). Separate path variables should be there for JDK and new JRE.
For example:
For JDK- D:\PROGRAM FILES\Java\jdk-15.0.2\bin
For JRE- C:\Program Files (x86)\Java\jre1.8.0_281\bin
Path system variable should point to the bin folder of wherever JRE installed.
Path system variables for JDK and JRE. SS from control panel:
I have a C++ application that uses JNI to create a Java virtual machine. I have the latest version of Java installed - JDK 8-144. If I run "java -version" it comes up and tells me that Java Hotspot 8 is the JVM. I have JAVA_HOME defined in the .profile file, and it works -- JAVA_HOME points to the JDK8-144 folder.
My application is including jni.h from the latest JDK. Our code creates a JVM with the JNI_VERSION_1_8 version flag. On Windows, this compiles and works perfectly.
The problem is that when we compile this code on the Mac, and use the JVM Framework for linking, we end up with an executable that, when run, says that there's "No Java Runtime present" and a dialog comes up that says we need to install the Version 6 JVM. This happens if we run the application from either the Bash terminal or from XCode.
I've researched this and there are other people who have had this identical issue. Everyone seems to suggest that JAVA_HOME needs to be pointing to the correct place, and mine is. Again, java -version works correctly. The whole thing is quite puzzling.
Does anyone know the right way to solve this? I've tried two different Macs with identical results. They are both running the latest version of macOS Sierra.
Thanks!
Dan
I am trying to launch an application (not Eclipse) that was written in Java. When I do, I get an error that says "Failed to Load the JNI shared Library (JDK)" along with a path that points to the location of the file.
From searching Google and StackOverflow, all I can find are people saying that the Java version installed needs to match my machine. My machine is 64 bit and so is my java installation, so I don't think that is my issue.
I have also verified that C:\Program Files\Java\jre7\bin is in my path variable. Also, just for the record, I do not use Eclipse. I have also tried uninstalling and reinstalling Java an the application that was written in Java. Lastly, the file it is complaining about exists on the machine.
Does anyone know what else could be the cause of this problem?
Update:
Thanks for your responses. I got it resolved, but the resolution seems like more of a hack and goes against what I was reading earlier. I installed the 32 bit version of Java 7 along side of my 64 bit version of Java 7. I then added the path the 32 bit version to the system path variable.
After I did this, the application was able to launch. Is there an issue with having both 64 bit and 32 bit versions of Java 7 installed simultaneously?
This is an error from your application. The application uses JNI. It is complaining that it cannot load it. Why it says (JDK) only its author knows. You will have to ask the author.
There is no problem having both versions of Java installed. However, the application you were using probably shipped with a 32-bit version of the JNI library. So, it needed to be used with a 32-bit Java JRE.
Sorry I couldn't be more specific with the question itself. Here's what I'm running: Windows 7 64bit, JDK v7, JRE v7 (64 bit), and JRE v6 (32 bit). I'm pretty new when it comes to Java, however I do know how to compile a program and all that stuff. I kept getting an error when I tried running my compiled programs:
C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1>javac ch3p1.java
C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1>java ch3p1
Error: could not open `C:\Program Files (x86)\Java\jre6\lib\i386\jvm.c
C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1>java -cp ch3p1
Error: could not open `C:\Program Files (x86)\Java\jre6\lib\i386\jvm.c
C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1>java cd3p1
Exception in thread "main" java.lang.NoClassDefFoundError: cd3p1
Caused by: java.lang.ClassNotFoundException: cd3p1
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: cd3p1. Program will exit.
C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1>java -version
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) Client VM (build 20.4-b02, mixed mode, sharing)
note that it couldn't find the file because I had changed the folder name to see if it would automatically detect the 64 bit JRE I have installed
However, after enough searching I found a page that stated my problems were because I was running a program I compiled on JDK v7 in JREv6. I messed around with that for a little while, trying to get it to run in the JRE that came with my download of JDK.
CD: C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1
Current directory: C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1
javac ch3p1.java
Process started >>>
<<< Process finished.
C:\Program Files\Java\jre7\bin\java.exe ch3p1
Process started >>>
Error: Could not find or load main class ch3p1
<<< Process finished.
I'm using Notepad++ and NppExec to compile faster, and I gave up trying to get it to run JRE v7 and just used the location of it. And here's my NppExec code (I don't know if it's important, but I'll post it anyways):
cd $(CURRENT_DIRECTORY)
javac $(FILE_NAME)
C:\Program Files\Java\jre7\bin\java.exe $(NAME_PART)
And, finally, here's the actual program I'm trying to get to run:
public class ch3p1
{
public static void main(String args[])
{
System.out.print("Hello.");
}
}
So, a quick recap. The first error I found out was because I was compiling and running a program with different versions of JDK and JRE. I couldn't figure out how to actually make it run with the JRE that came with my JDK installation so I used the direct path to it instead. My hopes got crushed that this would work when I went to run my compiled program. I got a simple "Error: Could not find or load main class ch3p1".
What's the question? I don't know exactly, the broad question is: What do I need to do to get this to work? I cannot be any more descriptive than that because I have no idea what to do or where to look next. I'm hoping I provided enough useful information and structured it well enough to make it comprehensible.
Some other questions: Will removing the two Java 6 updates in my Add/Remove Programs work? How do I change it so whenever it runs java, it'll run the 64bit JRE v7?
I have no idea what I'm doing here and I'm basically learning as I go. I am familiar with computers to an extent but I am new to Java and JDK so I don't know much about how it works. My leads might be completely misdirected and wrong, if so, please correct me.
EDIT
I understand that there are a lot of questions on this website and I'm sure the people posting here answer a lot of questions that can be solved with minimal to no effort involved. I have to say that I have looked everywhere and I came here to post this because I simply cannot find the solution to my problem. I wasn't looking for help on finding another program to use, and I definitely was not putting the files in my Java installation directory because despite me being new to Java, I am not new to programming. That response could have been easily avoided by looking at the first example I provided, and another one where the file path to my .java and .class files can be seen in a folder in my Documents.
I will list answers and what I have tried here:
I reinstalled JDK and JRE from the Oracle website
I have set my SET_HOME system variable and my Path system variable has the JDK bin directory in it.
My .class file and my .java file are in the same directory, and my class and the .java file are both named the same thing, including exact cases.
After I installed JDK and JRE I deleted my previous files and made a new one, and that didn't work either.
I tried putting the direct locations of java and javac as suggested in a reply.
I realize that there are better IDE and build programs out there, I am using javac because the class I am in right now is using javac.
Now, for some extra questions to help me out:
I have the Java v6.xx updates in my add/remove programs list, would removing these in any way effect anything in a positive or negative way. And would complete removal of all JDK/JRE files and re-installation change anything?
Is there any known issues with using Java and Windows 7 that I might be running into.
Is this an issue with JRE or JDK, because it seems to be compiling without any issues but when I go to run it is when I get the errors.
Are there any other variables other than CLASS_PATH or Path that I need to set?
I appreciate any and all help that's been given so far even though I haven't found a solution yet.
Try using the absolute path to the directory where you installed java. Here is what I would type on my machine
cd "C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1"
"C:\Program Files\Java\jdk1.7.0_02\bin\javac" ch3p1.java
"C:\Program Files\Java\jdk1.7.0_02\bin\java" ch3p1
if that works, you should add the directory to the path so that this is the preffered java version. This way you won't have to use the absolute path anymore and just type "java" and "javac" as usual
set PATH="C:\Program Files\Java\jdk1.7.0_02\bin\";%PATH%
Setting the path can also be done somewhere in the Control Panel so that you don't have to type that in each time you open a command prompt
Edit: You should probably set JAVA_HOME as well as "duffymo" suggests. If it still doesnt work there may be something wrong with your java installation. Try downloading and installing a new version from Oracle
Let's start by saying you should never, ever put any of your code in the directories where you installed Java JDK. Please make it a habit to create a separate folder (e.g. "c:\work") and put your project sub-folders there.
Open a command shell and type this: java -version. That will tell you the version of Java you're compiling and running with. You care about the JDK, because you're developing code.
Is your JAVA_HOME environment variable set? Please point it to the directory where you installed Java. Then add %JAVA_HOME%\bin to your PATH. If you do all this correctly, you should be able to compile in a command shell by typing javac.
So, create a folder c:\work\learning\src and put your ch3p1.java folder in it. Create a directory c:\work\learning\classes, too. Compile your code with this command:
javac -cp .;classes -d classes src\*.java
You should see ch3p1.class in the classes folder.
Run it with this command:
java -cp .;classes ch3p1
You'll see "Hello." in the console.
EDIT: I'd recommend that you read this tutorial carefully:
http://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html
You aren't the first person to compile and run "hello world". It seems to me that you're thrashing around too much. Simplify.
Several things here.
Java compiler can take a "target" argument to indicate for which Java version you wish to compile. By default, the target is the version of the current JVM.
So far, any class compiled with a given target is compatible with that target and any above version. So a class compiled for Java 5 is compatible with Java 5, 6 and 7.
To find out which version of Java you are running, type java -version in your terminal. It will output something like "Java 1.X..." The 'X' is the version of Java and you will often see people talking about Java 5 or Java 1.5 which is the same thing (same goes for 6 and 7).
The version that is running depends on several parameters, but usually it all comes down to the first Java bin directory in your 'PATH' environment variable.
Now, if you are considering Java IDE, there are 3 major ones:
Eclipse
NetBeans
IntelliJ
All three are fine Java IDE's and it is pretty much religious which one you will prefer. Personnally I use Eclipse.
Finally, for you problem:
Comiple using javac ch3p1.java
Run using java -cp . ch3p1
First of all I program in Netbeans IDE on Windows 7 x64.
I am using a java native library with dll's.
I was implementing the librarys in Netbeans and everything works fine!
But when I compile the project and try to run it via the command prompt "java -path/file.jar"
I am getting errors like: java.lang.UnsatisfiedLinkError. Can't load library
I could fix that by loading the dll in the program either with System.loadLibrary("WiiUsej") where i have to put the dll in the system32 folder
or by System.load("path/WiiUseJ.dll"). My goal anyway is to load the dll's from the same folder where the .jar file is. Does anybody know how this works?
The next problem is that after including the dll i get an error when i try to run the program on my 64 bit machine. Can't load IA 32-bit .dll on a 64 bit platform.
I was checking already for a solution on the internet which was saying i have to install a java 32 bit client.
I did that and ran it via "java -path/file.jar -d32"
Error: This Java instance does not support a 32-bit JVM
Maybe the solution is quiet simple but I was checking for hours on the internet and I am desperate! I dont get why it works when I run it in Netbeans and not in via the console.
Best regards
Make sure you start the 32 bit java.exe, not the (default) 64 bit one.
I expect that you are still using the 64 bit JVM. Run this command in the same shell that you are trying (and failing) to launch your application.
java -version
This will tell you which version of Java you are actually running.
If you are seeing the 64-bit one, you either need to change your shell's %PATH% variable, or use the full pathname for the 32-bit Java executable.