1

だから私はタブ付きのアプリケーションを作ろうとしています...しかし、ヌルポインタ例外でクラッシュし続けます。null ポインターの原因となっている可能性のあるすべての変数を調べたところ、絞り込んだと思います。

ListView activeList = (ListView) findViewById(R.id.activelist);
if(activeList == null) {
  Log.e("com.name.app", "activeList null");
}

これは null を返します。それはすべきですか?フラグメントを使用して、タブ付きレイアウトを構築しようとしています。これは参照しているxmlです。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    >

    <ListView
        android:id="@+id/activelist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:persistent="true" >    
    </ListView>

</LinearLayout>

助けてくれてありがとう!

編集:

    super.onCreate(savedInstanceState);
    setContentView(R.layout.tabs_layout);

それが私のコンテンツビューのようです。

編集:これは私の最終的なコードがどのように見えるかです!

    LayoutInflater inflater = (LayoutInflater)   getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    LinearLayout mContainer = (LinearLayout)     inflater.inflate(R.layout.tab_frag1_layout, null); 
    ListView activeList = (ListView) mContainer.findViewById(R.id.activelist);
4

2 に答える 2

4
LinearLayout mContainer = inflater.inflate(R.layout.linear_layout, null); 
ListView activeList = (ListView) mContainer.findViewById(R.id.activelist);

R.layout.linear_layout は、LinearLayoutあなたのListView.

于 2012-09-07T08:36:26.333 に答える
1

アクティビティで XML レイアウトを参照しましたか?

oncreate メソッドでこれを行うことができます。

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView.(R.layout.your_XML_file_name);
}
于 2012-09-07T08:21:59.040 に答える