2

私は何時間もデバッグしてきましたが、まだうまくいきません。Androidフラグメントを使ってRSSリーダーを作りました。Android を実行しているデバイスでは驚くほどうまく機能します4.0.x to 4.1.xが、Android デバイスでは起動時にクラッシュし4.2.xます。

私が得ることができる助けを本当に感謝します。

ログキャット:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.impsycho.androidpakistan/com.impsycho.androidpakistan.ItemListActivity}: 

android.view.InflateException: Binary XML file line #1: Error inflating class fragment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    at android.app.ActivityThread.access$600(ActivityThread.java:141)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5039)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
    at android.app.Activity.setContentView(Activity.java:1881)
    at com.impsycho.androidpakistan.ItemListActivity.onCreate(ItemListActivity.java:13)
    at android.app.Activity.performCreate(Activity.java:5104)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
... 11 more
Caused by: java.lang.NullPointerException
    at com.impsycho.androidpakistan.ItemListFragment$GetAllThePosts.onPreExecute(ItemListFragment.java:157)
    at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
    at android.os.AsyncTask.execute(AsyncTask.java:534)
    at com.impsycho.androidpakistan.ItemListFragment.onCreate(ItemListFragment.java:54)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:835)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061)
    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1160)
    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
    ... 20 more
Sending signal. PID: 30286 SIG: 9

主な活動:

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class ItemListActivity extends FragmentActivity implements ItemListFragment.Callbacks {
    private boolean mTwoPane;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_item_list);
        getActionBar().setDisplayShowTitleEnabled(false);

        if (findViewById(R.id.item_detail_container) != null) {
            mTwoPane = true;
            ((ItemListFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.item_list))
                    .setActivateOnItemClick(true);
        }
    }
    ...

activity_item_list.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/item_list"
    android:name="com.impsycho.androidpakistan.ItemListFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ItemListActivity" />

activity_item_twopane.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="?android:attr/dividerHorizontal"
    android:orientation="horizontal"
    android:showDividers="middle"
    tools:context=".ItemListActivity" >

    <fragment
        android:id="@+id/item_list"
        android:name="com.impsycho.androidpakistan.ItemListFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2.5" />

    <FrameLayout
        android:id="@+id/item_detail_container"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_weight="5" />

</LinearLayout>
4

1 に答える 1

1

さて、私は何が間違っていたのかを理解しました。

私は間違ったエラーに焦点を合わせていました。エラーは実際にGetAllThePosts()はアプリの起動時に呼び出される私のメソッドにあり、レイアウトを膨らませることができませんでした。また、他のすべての Android バージョンでも問題なく動作するため、エラーにはなりません。

viewAndroid 4.2.xでアプリ起動中はなぜかメニュー項目の変更ができません

責任のあるコードは次のとおりです。

private class GetAllThePosts extends AsyncTask<Void, Void, Void> {
        protected void onPreExecute() {
            RefreshMenuButton.setActionView(R.layout.action_progress);
            RefreshMenuButton.expandActionView();

            ...

Android 4.2 以降を使用しているかどうかを確認する条件ステートメントを追加しました。もしそうなら、それは初めて実行されません。

于 2013-01-18T02:39:34.247 に答える