Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to generate class file with java ASM?
    text
    copied!<p>I have tried</p> <pre><code> ClassWriter t = new ClassWriter(0); t.visitSource("testing.java", null); t.visitEnd(); byte d[] = t.toByteArray(); FileOutputStream p = null; try { p = new FileOutputStream("testing.class"); } catch (FileNotFoundException e) { e.printStackTrace(); } try { p.write(d); } catch (IOException e) { e.printStackTrace(); } </code></pre> <p>And the text within the testing.java is:</p> <pre><code>public class testing { public static void main(String args[]) { System.out.println("Works!"); } } </code></pre> <p>However, When I try to run the class file, it gives me this error:</p> <pre><code>Exception in thread "main" java.lang.UnsupportedClassVersionError: testing : Unsupported major.minor version 0.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) at java.lang.ClassLoader.defineClass(ClassLoader.java:615) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) </code></pre> <p>How would I fix it so that the class file would output "Works!" to the console?</p> <p><strong>Edit:</strong></p> <p>I don't want it to have to access the jdk files! (&lt;- Ex. javax.tools) That's why I was trying to get ASM to work.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload