无法编组值(有意图启动webview)?

时间:2013-10-21 18:05:56

标签: android android-intent android-fragments android-webview uri

我正在尝试从片段中打开webview。 webview是一项新活动。我一直收到一个我以前从未见过的错误,并且可以真正使用一些帮助搞清楚。

这是启动webview活动的片段:

public class TextFragment extends Fragment {

    private FuzzAdapter mAdapter;
    private ArrayList<Fuzzy> mFuzzies;
    public final String TAG = MainActivity.class.getSimpleName();

    public static TextFragment newInstance(ArrayList<Fuzzy> fuzzies) {
        TextFragment fragment = new TextFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("fuzzies", fuzzies);
        fragment.setArguments(bundle);
        return fragment;
    }

    @SuppressWarnings("unchecked")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ArrayList<Fuzzy> textArray = new ArrayList<Fuzzy>();
        int textType;
        String textData = null;

        mFuzzies = (ArrayList<Fuzzy>) getArguments().getSerializable("fuzzies");
        for (int i = 0; i < mFuzzies.size(); i++) {
            Fuzzy fuzzy = mFuzzies.get(i);
            if (fuzzy.mType == 0) {
                textType = fuzzy.mType;
                textData = fuzzy.mData;

                Fuzzy textFuzzy = new Fuzzy(textData, textType);
                textArray.add(textFuzzy);   
            }
        }

        mAdapter = new FuzzAdapter(new ArrayList<Fuzzy>(), getActivity());
        mAdapter.setFuzzList(textArray);
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.text_layout, container, false);

        if (mFuzzies.isEmpty()) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(getString(R.string.title));
            builder.setMessage(getString(R.string.error_message));
            builder.setPositiveButton(android.R.string.ok, null);
            builder.show();
        }

        ListView listView = (ListView) rootView.findViewById(R.id.listView0);
        listView.setAdapter(mAdapter);      
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view,
                    int position, long id) {

                Intent intent = new Intent(getActivity(),
                        FuzzWebViewActivity.class);
                intent.setData(Uri.parse("http://www.google.com/"));
                startActivity(intent);
            }
        });

        return rootView;
    }
}

以下是webview活动:

public class FuzzWebViewActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fuzz_web_view);

        Intent intent = getIntent();
        Uri fuzzUri = intent.getData();

        WebView webView = (WebView) findViewById(R.id.webView1);
        webView.loadUrl(fuzzUri.toString());

    }
}

这是logcat:

10-21 18:01:34.386: E/AndroidRuntime(2984): FATAL EXCEPTION: main
10-21 18:01:34.386: E/AndroidRuntime(2984): java.lang.RuntimeException: Parcel: unable to marshal value com.petesesto.fuzztest.behind.Fuzzy@40dd94b8
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Parcel.writeValue(Parcel.java:1235)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Parcel.writeList(Parcel.java:622)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Parcel.writeValue(Parcel.java:1195)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Parcel.writeMapInternal(Parcel.java:591)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Bundle.writeToParcel(Bundle.java:1627)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Parcel.writeBundle(Parcel.java:605)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:132)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Parcel.writeTypedArray(Parcel.java:1102)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:368)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Parcel.writeParcelable(Parcel.java:1254)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Parcel.writeValue(Parcel.java:1173)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Parcel.writeMapInternal(Parcel.java:591)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Bundle.writeToParcel(Bundle.java:1627)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Parcel.writeBundle(Parcel.java:605)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2252)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3052)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Handler.handleCallback(Handler.java:725)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.os.Looper.loop(Looper.java:137)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at android.app.ActivityThread.main(ActivityThread.java:5041)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at java.lang.reflect.Method.invokeNative(Native Method)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at java.lang.reflect.Method.invoke(Method.java:511)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-21 18:01:34.386: E/AndroidRuntime(2984):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

您需要使您的Fuzzy类实现Serializable或Parcelable接口。如果您需要帮助,请大声喊叫; - )