2016-08-29 5 views
-2

Ich versuche, andere Aktivität aufzurufen, aber es wirft Ausnahme. Hier ist der Code:Schwerwiegende Ausnahme wird in Intent geworfen

public static Intent newIntent(Context packageContext, boolean answerIsTrue) { 
    Intent i = newIntent(packageContext, answerIsTrue);//This line throwing exception 
    i.putExtra(EXTRA_ANSWER_IS_TRUE, answerIsTrue); 
    return i; 
}; 

Und die Logcat hier:

08-29 05:05:52.061 2457-2457/com.bbn.geoquiz E/AndroidRuntime: FATAL EXCEPTION: main 
Process: com.bbn.geoquiz, PID: 2457 
java.lang.StackOverflowError: stack size 8MB 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at com.bbn.geoquiz.CheatActivity.newIntent(CheatActivity.java:17) 
at 
08-29 05:05:53.550 2457-2457/com.bbn.geoquiz E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 17527860) 
08-29 05:05:53.550 2457-2457/com.bbn.geoquiz E/AndroidRuntime: Error reporting crash 
android.os.TransactionTooLargeException: data parcel size 17527860 bytes 
    at android.os.BinderProxy.transactNative(Native Method) 
    at android.os.BinderProxy.transact(Binder.java:503) 
    at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4425) 
    at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:90) 
    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693) 
    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690) 

Könnten Sie bitte beraten, wie dieser Fehler zu beheben?

+0

'Intent i = newIntent (packageContext, answerIsTrue);' ', wo neue Intent (#Context, #class);', aber sie sind vorbei boolean – Sanoop

+1

Wo Sie stattdessen den Klassennamen geben werden sollte, von boolean als zweiten Parameter zu übergeben – Sanoop

+0

@Sanoop, danke, lass mich versuchen, die Signatur zu ändern. –

Antwort

0

Sie Endlosschleife führen, sollten Code sein:

public static Intent newIntent(Context packageContext, Class<?> clazz, boolean answerIsTrue) { 
    Intent i = new Intent(packageContext, clazz); 
    i.putExtra(EXTRA_ANSWER_IS_TRUE, answerIsTrue); 
    return i; 
} 
0

Sie rekursiv die gleiche Methode aufrufen, ohne an der genannten Linie zu stoppen.

Intent i = newIntent(packageContext, answerIsTrue); 

Bitte beheben Sie die Logik in Ihrem Code-Flow.

1

Dies sind die öffentlichen Konstruktoren für Intent

Intent() 

eine leere Absicht erstellen.

Intent(Intent o) 

Kopieren Konstruktor.

Intent(String action) 

Erstellen Sie eine Absicht mit einer bestimmten Aktion.

Intent(String action, Uri uri) 

Erstellen Sie eine Absicht mit einer bestimmten Aktion und für eine bestimmte Daten-URL.

Intent(Context packageContext, Class<?> cls) 

Erstellen Sie eine Absicht für eine bestimmte Komponente.

Erstellen Sie eine Absicht für eine bestimmte Komponente mit einer angegebenen Aktion und Daten.

In your case you are passing boolean as the second parameter, where you need to pass the class name as the second parameter

+0

wow perfekt ... (Y) –

+0

@ andrey.shedko sollte es eine akzeptierte Antwort sein. –

+0

_In deinem Fall übergibst du boolean als zweiten Parameter, ..._ --- Er ruft wiederholt seine eigene Implementierung von 'newIntent' auf. Das ist der Grund für 'StackOverflowError'. – ozbek

Verwandte Themen