tags:

views:

1029

answers:

2

This is one of those cases where I had the code working, tried to add something else, and then found that my previous code has stopped working. It crashes when the program starts. The error seems to lie with the definition of the ArrayAdapter custom class, as if I try using a built in adapter, it works fine. Any help?

public class MainEntry extends ListActivity{    

private String[] items = {"yay","yay2","asdfa","nlah","lipsum","orum","rawr"};



/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setListAdapter(new IconicAdapter());
}


class IconicAdapter extends ArrayAdapter {
    IconicAdapter(){
        super(MainEntry.this, R.layout.post_obj, items);
    }

    public View getView(int pos, View convertView, ViewGroup parent){
        LayoutInflater inf = getLayoutInflater();

        View row = null;
        if(convertView==null){
            inf.inflate(R.layout.post_obj, parent, false);
        }else{
            row = convertView;
        }
        inf.inflate(R.layout.post_obj, parent, false);

        TextView label = (TextView) row.findViewById(R.id.label);
        label.setText(items[pos]);

        ImageView image = (ImageView) row.findViewById(R.id.icon);
        image.setImageResource(((Math.random()>.5)?R.drawable.wolfire:R.drawable.android)); //temp

        return row;
    }

}

}

Here's the LogCat log if it helps:

12-29 23:43:49.968: INFO/ActivityManager(564): Start proc com.test.TestApp for 

activity com.test.TestApp/.MainEntry: pid=783 uid=10023 gids={1015}
12-29 23:43:50.118: INFO/jdwp(783): received file descriptor 10 from ADB
12-29 23:43:50.188: DEBUG/ddm-heap(783): Got feature list request
12-29 23:43:50.318: WARN/ActivityThread(783): Application com.test.TestApp is waiting for the debugger on port 8100...
12-29 23:43:50.348: INFO/System.out(783): Sending WAIT chunk
12-29 23:43:50.348: INFO/dalvikvm(783): Debugger is active
12-29 23:43:50.577: INFO/System.out(783): Debugger has connected

12-29 23:43:50.577: INFO/System.out(783): waiting for debugger to settle...
12-29 23:43:50.638: INFO/ARMAssembler(564): generated scanline__00000077:03515104_00001001_00000000 [ 64 ipp] (84 ins) at [0x2c2900:0x2c2a50] in 1189200 ns
12-29 23:43:50.778: INFO/System.out(783): waiting for debugger to settle...
12-29 23:43:50.987: INFO/System.out(783): waiting for debugger to settle...
12-29 23:43:51.187: INFO/System.out(783): waiting for debugger to settle...
12-29 23:43:51.387: INFO/System.out(783): waiting for debugger to settle...
12-29 23:43:51.597: INFO/System.out(783): waiting for debugger to settle...
12-29 23:43:51.800: INFO/System.out(783): waiting for debugger to settle...
12-29 23:43:52.003: INFO/System.out(783): waiting for debugger to settle...
12-29 23:43:52.206: INFO/System.out(783): waiting for debugger to settle...
12-29 23:43:52.218: INFO/ActivityManager(564): Killing process com.test.TestApp (pid=783) at user's request
12-29 23:43:52.228: INFO/Process(564): Sending signal. PID: 783 SIG: 9
12-29 23:43:52.238: INFO/ActivityManager(564): Process com.test.TestApp (pid 783) has died.
12-29 23:43:52.298: WARN/UsageStats(564): Unexpected resume of com.android.launcher while already resumed in com.test.TestApp
12-29 23:43:52.348: WARN/InputManagerService(564): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43944340
12-29 23:43:57.517: DEBUG/dalvikvm(719): GC freed 726 objects / 64112 bytes in 83ms
A: 

Ahhh... I am such an idiot. Lol. I didn't actually set 'row' to the value of inf.inflate().

Facepalm Yup. Disregard this. Well hopefully someone else will find the code useful.

GuyNoir
A: 

Your right (row = inf.inflate...), and you should had a NullPointerException. Plus, you must remove the second call "inf.inflate(R.layout.post_obj, parent, false);" otherwise, you'll lose the optimization granted by the convertView...

Fabien