最近写了一个GWT类,出现了这个错误。
java.lang.ClassFormatError: Illegal method name "<init>$"
丈二和尚摸不着头脑,都些什么鬼提示啊!
谷歌了一下发现有人重现了这个错误:
Main:
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsonUtils;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
public class _37_OverLayStackOverfflowQuestion implements EntryPoint {
String jsonS = "{\"hello\":\"world\"}";
public void onModuleLoad() {
JavaScriptObject jso = JsonUtils.safeEval(jsonS);
DataUtil overlayEr = jso.cast();
OtherOverlay wellwell = jso.cast();
overlayEr.test(wellwell);
Window.alert("works");
}
}
First overlay:
import java.util.List;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;
public final class DataUtil extends JavaScriptObject {
protected DataUtil() {
}
public final native void test(OtherOverlay json) /*-{
return;
}-*/;
}
Second Overlay:
import com.google.gwt.core.client.JavaScriptObject;
public class OtherOverlay extends JavaScriptObject {
protected OtherOverlay() {
}
public final native void someFkt()/*-{
alert('hello');
}-*/;
int i = 0;
}
The error is in the last page in of the second Overlay class: int i = 0;
.
However the error message comes up in DataUtil.
java.lang.ClassFormatError: Illegal method name "<init>$" in class stefan/client/DataUtil
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at com.google.gwt.dev.shell.CompilingClassLoader.findClass(CompilingClassLoader.java:1085)
I guess your error ocures in one of your overlay classes. Check if each of those works alone!
提示说 int i = 0报错。然后看看自己的类,提示一点帮助也没有。仔细再看一下,恍然大悟,原来重点在这里:I guess your error ocures in one of your overlay classes. Check if each of those works alone!
意思说这个错误是它引入的某个类编译失败了,而怎么失败的,GWT只追踪到了java.lang.ClassFormatError。只能由自己仔细检查了,仔细一看原来引入的类我在JavaScriptObject继承类忘记写protected的构造方法了。而GWT的编译,就挂在前一个类这里了,还报了这么奇怪个错误!