我在"java testphase"之后得到这个错误:
C:jasmin-2.4>java testphase
Exception in thread "main" java.lang.VerifyError:
(class: testphase, method: main signature: ([Ljava/lang/String;)V)
Expecting to find object/array on stack
Could not find the main class: testphase.
Program will exit.
代码:.class public testphase
.super java/lang/Object
; standard initializer
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit stack 10
.limit locals 3
; assign something
iconst_1
iconst_1
iadd
istore_1
; assign something
iconst_2
iconst_2
isub
istore_2
; Writeln
getstatic java/lang/System/out Ljava/io/PrintStream;
iload_1
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
return
.end method
你有很多问题。
首先:你需要改变最后的
iload_1
aload_1
- 你正在加载String数组参数,所以不应该使用整数load (load)来加载。
第二,你正在加载一个String数组,而不是String。你需要选择你想要的元素。(如何解引用数组中的元素,请参阅aaload)
可以:
.class public testphase
.super java/lang/Object
; standard initializer
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit stack 2
.limit locals 3
; assign something
iconst_1
iconst_1
iadd
istore_1
; assign something
iconst_2
iconst_2
isub
istore_2
; Writeln
getstatic java/lang/System/out Ljava/io/PrintStream;
iload_1
invokevirtual java/io/PrintStream/println(I)V
; Writeln variable 2
getstatic java/lang/System/out Ljava/io/PrintStream;
iload_2
invokevirtual java/io/PrintStream/println(I)V
return
.end method
基本变化包括System.out.println(int)
的签名。