该死的 java.lang.ClassFormatError: Illegal method name "<init>$" 错误

本文介绍了一次在使用GWT开发过程中遇到的编译错误,并详细解释了如何通过逐步排查找到问题根源,最终解决了一个关于JavaScriptObject继承类中构造方法缺失的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近写了一个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的编译,就挂在前一个类这里了,还报了这么奇怪个错误!



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FoxMale007

文章非V全文可读,觉得好请打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值