-1

This line of code in my Python file seems to return the error:

Could not find or load main class TestClass

TestClass.java is in the same folder as my .py file. Not sure what is going wrong. Any ideas?

process = Popen(['java', 'TestClass'], stdout=PIPE)

Edit: compiling the java file worked, however now i am getting the following error when trying to run it. i tested the java file directly and it worked fine, so it seems to be an issue with python to java versions? i am running java 8 latest build now, and latest build of python...

Exception in thread "main" java.lang.UnsupportedClassVersionError: TestClass : Unsupported major.minor version 52.0
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(Unknown Source)
   at java.security.SecureClassLoader.defineClass(Unknown Source)
   at java.net.URLClassLoader.defineClass(Unknown Source)
   at java.net.URLClassLoader.access$100(Unknown Source)
   at java.net.URLClassLoader$1.run(Unknown Source)
   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.ClassLoa`enter code here`der.loadClass(Unknown Source)
   at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Niko
  • 67
  • 1
  • 4
  • Has `TestClass` been compiled to a `.class` file? – Joe C Jul 25 '17 at 22:39
  • no i just have the .java file. perhaps that is the problem. :) – Niko Jul 26 '17 at 02:58
  • Does it work when you issue `java TestClass` from your Terminal? – zwer Jul 26 '17 at 21:44
  • yes it works when i run java TestClass, it only throws the error when i run the python .py file which calls the above code... the only JRE and JDK i appear to have installed is the latest 1.8 version...so not sure what in the world is occurring.. – Niko Jul 26 '17 at 22:07

1 Answers1

0

Your python script is looking for a compiled .class file, while you only have the uncompiled .java file.

user2357112
  • 260,549
  • 28
  • 431
  • 505
Joe C
  • 15,324
  • 8
  • 38
  • 50