很奇怪的错误。我正在尝试在我的 android 应用程序中的非活动类中实现一个简单的接口。但是,我得到一个运行时错误。如果我删除实现,代码可以正常工作。我会让代码自己说话,随时插话。谢谢!
这在实例化 Globals 的实例时会引发 ClassNotFoundException
public class Globals implements IReceivable {
private volatile static Globals uniqueGlobal;
private static ClientSocket clientSocket;
private Globals()
{
}
public static Globals getInstance() {
synchronized (Globals.class) {
if (uniqueGlobal == null) {
uniqueGlobal = new Globals();
uniqueGlobal.InitializeClient();
}
}
return uniqueGlobal;
}
@Override
public void MessageReceived(UUID clientId, String message) {
// TODO Auto-generated method stub
}
}
当我删除它时,一切正常
public class Globals {
private volatile static Globals uniqueGlobal;
private static ClientSocket clientSocket;
private Globals()
{
}
public static Globals getInstance() {
synchronized (Globals.class) {
if (uniqueGlobal == null) {
uniqueGlobal = new Globals();
uniqueGlobal.InitializeClient();
}
}
return uniqueGlobal;
}
}
编辑
这是 IReceivable 接口
public interface IReceivable {
public void MessageReceived(UUID clientId, String message);
}
以及确切的错误:
12-02 10:14:15.859: E/AndroidRuntime(546): java.lang.NoClassDefFoundError: com.example.utilities.Globals
引发错误的行如下所示:
Globals global = Globals.getInstance();