newInstance失败:没有<init>

Bod*_*ger 10 android

我无法实例化子活动.在logcat中我看到这一行:

01-22 15:14:38.906: DEBUG/dalvikvm(411): newInstance failed: no <init>()
Run Code Online (Sandbox Code Playgroud)

这是dalvik中生成该logcat的行.

/*
 * public T newInstance() throws InstantiationException, IllegalAccessException
 *
 * Create a new instance of this class.
 */
static void Dalvik_java_lang_Class_newInstance(const u4* args, JValue* pResult)
...
    /* find the "nullary" constructor */
    init = dvmFindDirectMethodByDescriptor(clazz, "<init>", "()V");
    if (init == NULL) {
        /* common cause: secret "this" arg on non-static inner class ctor */
        LOGD("newInstance failed: no <init>()\n");
        dvmThrowExceptionWithClassMessage("Ljava/lang/InstantiationException;",
            clazz->descriptor);
        RETURN_VOID();
    }
Run Code Online (Sandbox Code Playgroud)

以下是我在计时器处理程序中激活活动的操作.

// move on to Activation
// ePNSplash is this activity a splash screen

Intent i = new Intent (ePNSplash.this, Activation.class);
startActivity (i);
Run Code Online (Sandbox Code Playgroud)

我尝试启动的活动是活动上方的2个扩展

这是第一个扩展

public abstract class AndroidScreen extends Activity {
    ....

public AndroidScreen (String title, AndroidScreen parent, AndroidScreen main)
{
    super ();

    myGlobals = Globals.getGlobals ();

    myGlobals.myLogger.logString("AndroidScreen: 001");

    myParent = parent;
    myMainScreen = main;
    myTitle = title;
}
Run Code Online (Sandbox Code Playgroud)

这只是构造函数,它似乎是有问题的部分.这是第二个扩展和我试图实例化的类.

public class Activation extends AndroidScreen {

public Activation (String title, AndroidScreen parent, AndroidScreen main)
{
    super (title, parent, main);
}
Run Code Online (Sandbox Code Playgroud)

我绝对困惑,我有一个构造函数,我确保我调用我的超级构造函数,可能是什么错误?

谢谢

朱利安

Ell*_*hes 20

dalvikvm正在寻找一个零参数构造函数(这就是"nullary"的含义,如2个参数的"binary",1个参数的"unary",0个参数的"nullary").

在您展示的代码段中,您只有一个三参数构造函数.这不好:你将被实例化而没有参数,所以你需要一个零参数构造函数.

  • 我的问题是IntentService,抽象类没有定义默认构造函数,只有带参数的构造函数(String name).结果,我对编译器实现默认构造函数感到困惑并将其关闭.当我将其添加为MyIntentService(){super(null); 这一切都奏效了.这是非常直观的 - 感谢这个例外的q&a. (2认同)