Axiom
Axiom

Reputation: 37

Android: ListView Custom Adapter. Resource not found Error

Error Log:

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 Class:

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;

}

Now the error seems to occur when I attempt to change the text of the textView_Class. It says the resource could not be found.

Also I am setting the ListAdapter via

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);

Upvotes: 0

Views: 1129

Answers (2)

Ashutosh Verma
Ashutosh Verma

Reputation: 338

Show your List item layout... R.layout.listview_characters_content

Upvotes: 0

Mukesh Rana
Mukesh Rana

Reputation: 4091

From the Exception, it looks you are setting some int value to your TextView. When you are setting an int value to your TextView, it thinks that you are trying to set the text with a String resource with ID equal to your int value which in your case may be this guardian.getCharacterBase().getClassType(). Try replacing your this line

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

with this

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

Upvotes: 2

Related Questions