2016-01-24 44 views
0

錯誤日誌:Android:ListView自定義適配器。未找到資源錯誤

android.content.res.Resources$NotFoundException: String resource ID #0x0 
                          at android.content.res.Resources.getText(Resources.java:299) 
                          at android.widget.TextView.setText(TextView.java:4138) 
                          at me.axiom.aapp.ironbannercompanion.ListViewAdapter.getView(ListViewAdapter.java:43) 
                          at android.widget.AbsListView.obtainView(AbsListView.java:2347) 
                          at android.widget.ListView.measureHeightOfChildren(ListView.java:1270) 
                          at android.widget.ListView.onMeasure(ListView.java:1182) 
                          at android.view.View.measure(View.java:17565) 
                          at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:727) 
                          at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463) 
                          at android.view.View.measure(View.java:17565) 
                          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537) 
                          at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) 
                          at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135) 
                          at android.view.View.measure(View.java:17565) 
                          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537) 
                          at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:391) 
                          at android.view.View.measure(View.java:17565) 
                          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537) 
                          at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) 
                          at android.view.View.measure(View.java:17565) 
                          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537) 
                          at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) 
                          at android.widget.LinearLayout.measureVertical(LinearLayout.java:722) 
                          at android.widget.LinearLayout.onMeasure(LinearLayout.java:613) 
                          at android.view.View.measure(View.java:17565) 
                          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5537) 
                          at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) 
                          at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2615) 
                          at android.view.View.measure(View.java:17565) 
                          at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2045) 
                          at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1196) 
                          at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1409) 
                          at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1084) 
                          at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5990) 
                          at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) 
                          at android.view.Choreographer.doCallbacks(Choreographer.java:580) 
                          at android.view.Choreographer.doFrame(Choreographer.java:550) 
                          at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) 
                          at android.os.Handler.handleCallback(Handler.java:739) 
                          at android.os.Handler.dispatchMessage(Handler.java:95) 
                          at android.os.Looper.loop(Looper.java:135) 
                          at android.app.ActivityThread.main(ActivityThread.java:5343) 
                          at java.lang.reflect.Method.invoke(Native Method) 
                          at java.lang.reflect.Method.invoke(Method.java:372) 
                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 

ListViewAdapter類:

String url="http://bungie.net"; 

private Context context; 
private GuardianInfo[] guardianList; 
private LayoutInflater inflater; 

public ListViewAdapter(Context context, int resource, GuardianInfo[] object) { 
    super(context, resource, object); 
    this.context = context; 
    this.guardianList = object; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 

    if (inflater == null) 
     inflater = (LayoutInflater) context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    if (convertView == null) 
     convertView = inflater.inflate(R.layout.listview_characters_content, parent, false); 

    GuardianInfo guardian = guardianList[position]; 

    TextView textView_Class = (TextView) convertView.findViewById(R.id.listView_CLASS); 
    textView_Class.setText(guardian.getCharacterBase().getClassType()); 

    ImageView imageView_IMG = (ImageView) convertView.findViewById(R.id.listView_IMG); 
    ImageView imageView_BG = (ImageView) convertView.findViewById(R.id.listView_BG); 

    Picasso.with(context).load(url + guardian.getEmblemPath()).into(imageView_IMG); 
    Picasso.with(context).load(url + guardian.getBackgroundPath()).into(imageView_BG); 

    return convertView; 

} 

現在錯誤似乎發生時,我試圖改變textView_Class的文本。它說該資源找不到。

而且我通過

GuardianInfo[] guardians = response.body().getResponse().getData().getCharacters(); 

ListViewAdapter adapter = new ListViewAdapter(getBaseContext(), R.layout.listview_characters_content, guardians); 

ListView listView_Characters = (ListView) findViewById(R.id.listView_Characters); 
listView_Characters.setAdapter(adapter); 
+1

什麼guardian.getCharacterBase()。getClassType()返回?如果它返回一個整數,你必須小心,因爲它是由setText作爲資源ID來處理的,而不是作爲一個字符串來顯示。 – thetonrifles

回答

1

設置ListAdapter從異常,它看起來要設置一些int值到您的TextView。當你爲你的TextView設置一個int值時,它認爲你正在嘗試使用ID等於你的int值的字符串資源來設置文本,在你的情況下這可能是這個guardian.getCharacterBase().getClassType()。嘗試用這種

textView_Class.setText(String.valueOf(guardian.getCharacterBase().getClassType())); 
+0

是的,它返回一個整數。我要做的是根據整數是什麼來改變文本。 – Axiom

0

顯示您的列表項目佈局免去您此行

textView_Class.setText(guardian.getCharacterBase().getClassType()); 

... R.layout.listview_characters_content

相關問題