2016-03-25 5 views
-1

私はアプリケーションで送信されたアイテムを表示するのにlistviewを使用したいと思いますが、アプリケーションがクラッシュし、私のログカットで次のメッセージが表示される "java.lang.RuntimeException:あなたのコンテンツには、id属性が 'android.R.id.list'であるListViewが必要です。 私はこのフォーラムで解決策を探していましたが、あなたが見たいと思ったIDで既にリストビューを持っていますが、エラーはまだポップアップしています。どこが間違っていますか?助けてください。ここjava.lang.RuntimeException:あなたのコンテンツは、id属性が 'android.R.id.list'であるListViewを持っている必要があります

は私DisplaySentItemsActivityです:

package zw.ac.msu.kuda.e_servives; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.widget.ListView; 

import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 

public class DisplaySentItemsActivity extends AppCompatActivity { 
String json_sentitems; 
JSONObject jsonObject; 
JSONArray jsonArray; 
SentItemsAdapter sentItemsAdapter; 
ListView listView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_display_sent_items); 
    listView =(ListView) findViewById(android.R.id.list); 
    listView.setAdapter(sentItemsAdapter); 
    sentItemsAdapter=new SentItemsAdapter(this,R.layout.fragment_sentitems);       
    json_sentitems=getIntent().getExtras().getString("json_data"); 
    try { 

     jsonObject=new JSONObject(json_sentitems); 
     jsonArray=jsonObject.getJSONArray("server_response"); 
     int count=0; 
     int id; 
     String email, dateSent, subject, body, attachments; 
     while(count<jsonArray.length()) { 
      JSONObject finalObject = jsonArray.getJSONObject(0); 
      id = finalObject.getInt("id"); 
      email = finalObject.getString("email"); 
      dateSent = finalObject.getString("dateSent"); 
      subject = finalObject.getString("subject"); 
      body = finalObject.getString("body"); 
      attachments = finalObject.getString("attachments"); 
      SentItems sentItems=new SentItems(subject,dateSent,body,attachments,id); 
      sentItemsAdapter.add(sentItems); 
      count++; 
     } 

    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 

} 

}

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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" 

tools:context="zw.ac.msu.kuda.e_servives.DisplaySentItemsActivity"> 
<ListView 
android:id="@android:id/list" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
/> 

</RelativeLayout> 

答えて

0

変更

<ListView 
android:id="@android:id/list" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
/> 
with this 
<ListView 
android:id="@+id/list" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
/> 

この

listView =(ListView) findViewById(android.R.id.list); 

with this

listView =(ListView) findViewById(R.id.list); 
関連する問題