2010-01-22 2 views
10

하위 작업을 인스턴스화 할 수 없습니다. logcat에서 나는이 줄을 보았습니다 :newInstance failed : no <init>

01-22 15:14:38.906: DEBUG/dalvikvm(411): newInstance failed: no <init>() 

이것은 logcat을 생성하는 dalvik의 줄입니다.

/* 
* 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(); 
    } 

다음은 타이머 처리기에서 활동을 활성화하기 위해 취하는 조치입니다.

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

Intent i = new Intent (ePNSplash.this, Activation.class); 
startActivity (i); 

내가 시작하려고 활동은 여기에

첫 번째 확장

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; 
} 

이있는 부분이 될 것으로 보인다 유일한 생성자입니다 활동 위의 2 개 확장입니다 문제. 여기에 두 번째 확장 기능과 인스턴스화하려고하는 클래스가 있습니다.

public class Activation extends AndroidScreen { 

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

전 생성자가 있습니다. 제 슈퍼 생성자를 호출했는지, 틀릴 수도 있습니다.

답변

20

dalvikvm 년대 즉 1 개 인수, 2 개 인수에 대한 "진" "단항"에서, 그들은 "인수 없음"을 의미하는 무엇 (제로 인수 생성자를 찾고, 그것의 당신에게

줄리안 감사 0 인수의 경우는 「무효」

표시된 스 니펫에는 3 가지 인수 생성자 만 있습니다. 그건 좋지 않습니다. 당신은 아무 인자없이 인스턴스화 될 것이고, 따라서 인자없는 생성자가 필요합니다.

+0

감사합니다. – Bodger

+2

내 문제는 추상 클래스가 기본 생성자를 정의하지 않고 인수 (문자열 이름)가있는 생성자 만 정의한 IntentService입니다. 결과적으로 컴파일러가 기본 생성자를 구현하는 것에 혼란을 느끼고 그만 두었습니다. MyIntentService() {super (null); } 모두 효과가있었습니다. 이것은 매우 직관적이었습니다 -이 예외에 대한 q & a에 감사드립니다. – mobibob

+0

나는이 일을 할 때 내 눈을 믿을 수 없었다 !!! 내가 파편을 인스턴스화하고 미리 팽창 시켰으며 이것을 읽었을 때 제로 인수가 추가되었고 효과가있었습니다. Whos 내가 이것을 더 upvote 할 수 있었다! –