包裹:无法编组价值 - 碎片

时间:2013-11-14 12:55:57

标签: android android-intent android-fragments marshalling parcelable

当我尝试在浏览器上启动导航时,我的应用程序崩溃了。我已经阅读了有关实现Parcelable(here)的内容,但我对如何实现它并不知情。

这是我第一次使用Fragments并且他们是PIA。我通过添加两个标签修改了this project

我得到的错误: logcat的:

    11-14 13:37:22.867: E/AndroidRuntime(671): FATAL EXCEPTION: main
11-14 13:37:22.867: E/AndroidRuntime(671): java.lang.RuntimeException: Parcel: unable to marshal value AppTabAFirstFragment{414df8c8 #0 id=0x1010000}
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeValue(Parcel.java:1235)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeList(Parcel.java:622)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeValue(Parcel.java:1195)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeMap(Parcel.java:575)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeValue(Parcel.java:1166)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Bundle.writeToParcel(Bundle.java:1619)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Parcel.writeBundle(Parcel.java:605)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2078)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.app.ActivityThread$StopInfo.run(ActivityThread.java:2874)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Handler.handleCallback(Handler.java:615)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Handler.dispatchMessage(Handler.java:92)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.os.Looper.loop(Looper.java:137)
11-14 13:37:22.867: E/AndroidRuntime(671):  at android.app.ActivityThread.main(ActivityThread.java:4745)
11-14 13:37:22.867: E/AndroidRuntime(671):  at java.lang.reflect.Method.invokeNative(Native Method)
11-14 13:37:22.867: E/AndroidRuntime(671):  at java.lang.reflect.Method.invoke(Method.java:511)
11-14 13:37:22.867: E/AndroidRuntime(671):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-14 13:37:22.867: E/AndroidRuntime(671):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-14 13:37:22.867: E/AndroidRuntime(671):  at dalvik.system.NativeStart.main(Native Method)

App Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.lupradoa.lakari"
    android:versionCode="1"
    android:versionName="1.0">
     <uses-permission android:name="android.permission.INTERNET" />

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" />

    <application android:label="@string/app_name"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/AppTheme"
        android:allowBackup ="false">

        <activity android:name="com.lupradoa.lakari.base.AppMainTabActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    <intent-filter>       
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
    </application>

</manifest>

我收到错误的代码: FragmentA.java:

    package com.lupradoa.lakari.fragmenttabstudy.tabA;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import com.lupradoa.lakari.R;
import com.lupradoa.lakari.base.BaseFragment;

public class AppTabAFirstFragment extends BaseFragment {
    private Button mGotoButton;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view       =   inflater.inflate(R.layout.app_tab_a_first_screen, container, false);

        mGotoButton =   (Button) view.findViewById(R.id.goToShop);
        mGotoButton.setOnClickListener(listener);

        return view;
    }

    private OnClickListener listener        =   new View.OnClickListener(){
        @Override

        public void onClick(View v) {
            Intent navigation = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?f=d&daddr=42.338803,-7.863178"));

            navigation.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try{ 
                startActivity(navigation);
            }catch(ActivityNotFoundException anf){
                Log.w(TAG, "Navigation not installed");
            }
        }
    };


    /*
    public static class MyParcelable implements Parcelable {
        private int mData;

        public int describeContents() {
            return 0;
        }

        public void writeToParcel(Parcel out, int flags) {
            out.writeInt(mData);
        }

        public static final Parcelable.Creator<MyParcelable> CREATOR
                = new Parcelable.Creator<MyParcelable>() {
            public MyParcelable createFromParcel(Parcel in) {
                return new MyParcelable(in);
            }

            public MyParcelable[] newArray(int size) {
                return new MyParcelable[size];
            }
        };

        private MyParcelable(Parcel in) {
            mData = in.readInt();
        }
    }
  */

}

根据Android Reference,底部是Parcelable的“典型实现”,但在互联网上查找了一些样本后,我无法实现它。

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:1)

我猜你已经弄乱了你的活动的生命周期方法。启动Google地图后,系统会调用您的活动的onPause()onSaveInstanceState()onStop()方法。有可能你搞砸了那里的东西。我发布的内容并没有看到任何不好的内容。

答案 1 :(得分:0)

我已打开原始项目,该按钮会在浏览器上启动Google地图而不会导致应用崩溃。有些东西可能会被破坏。