Intent中会抛出致命异常

时间:2016-08-29 05:11:35

标签: android android-intent

我正在尝试调用其他Activity,但它正在抛出异常。这是代码:

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

这里的Logcat:

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)

您能否告知如何解决此错误?

3 个答案:

答案 0 :(得分:1)

这些是Intent

的公共构造函数
Intent()

创建一个空意图。

Intent(Intent o)

复制构造函数。

Intent(String action)

使用给定的操作创建一个意图。

Intent(String action, Uri uri)

使用给定操作和给定数据网址创建意图。

Intent(Context packageContext, Class<?> cls)

为特定组件创建意图。

Intent(String action, Uri uri, Context packageContext, Class<?> cls)

为具有指定操作和数据的特定组件创建意图。

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

答案 1 :(得分:0)

你正在造成无限循环,代码应该是:

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

答案 2 :(得分:0)

您正在递归调用相同的方法而不停在上述行。

Intent i =  newIntent(packageContext, answerIsTrue);

请修复代码流中的逻辑。