开发者

Unable to fill List Layout in App

开发者 https://www.devze.com 2022-12-18 08:27 出处:网络
I\'m attempting to write my first android app and am having a little problem with filling a List Layout from a DB.

I'm attempting to write my first android app and am having a little problem with filling a List Layout from a DB.

The project itself is here:

http://code.google.com/p/biofuelsfinder/

However the specific code I'm having the problem with is here:

public void fillData(String fueltype){
        ArrayList<String> items = new ArrayList<String>();
        Cursor retailers = biofuelsDB.getRetailers("b5");
        /*while(!retailers.isAfterLast()){
                retailers.moveToNext();
                try{
                    items.add(retailers.getString(retailers.getColumnIndex("name")));
                } catch(IllegalStateException e){
                    String msg = e.getMessage();
                }
                //items.add(user.lastName);
                //items.add(user.country);
        }*/

        items.add("Blah1");
        items.add("Blah2");
        items.add("Blah3");

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
             R.layout.retailers_row, items);
        /*setListAdapter(adapter);*/
}

The two portions commented out, if run cause and illegalStateException error which then aborts the code.

If anyone could have a look and let me know what I'm going wrong that would be most appreciated.

Below is the stacktrace

W/dalvikvm(  208): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime(  208): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime(  208): java.lang.IllegalStateException: Could not execute method of the activity
E/AndroidRuntime(  208):    at android.view.View$1.onClick(View.java:2031)
E/AndroidRuntime(  208):    at android.view.View.performClick(View.java:2364)
E/AndroidRuntime(  208):    at android.view.View.onTouchEvent(View.java:4179)
E/AndroidRuntime(  208):    at android.widget.TextView.onTouchEvent(TextView.java:6532)
E/AndroidRuntime(  208):    at android.view.View.dispatchTouchEvent(View.java:3709)
E/AndroidRuntime(  208):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
E/AndroidRuntime(  208):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
E/AndroidRuntime(  208):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
E/AndroidRuntime(  208):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
E/AndroidRuntime(  208):    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
E/AndroidRuntime(  208):    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
E/AndroidRuntime(  208):    at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
E/AndroidRuntime(  208):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
E/AndroidRuntime(  208):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1690)
E/AndroidRuntime(  208):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  208):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  208):    at android.app.ActivityThread.main(ActivityThread.java:4310)
E/AndroidRuntime(  208):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  208):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  208):    at com.android开发者_运维技巧.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(  208):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(  208):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  208): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime(  208):    at com.biofuelsfinder.biofuelsfinder.buttonClickHandler(biofuelsfinder.java:37)
E/AndroidRuntime(  208):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  208):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  208):    at android.view.View$1.onClick(View.java:2026)
E/AndroidRuntime(  208):    ... 21 more
E/AndroidRuntime(  208): Caused by: java.lang.NullPointerException
E/AndroidRuntime(  208):    at com.biofuelsfinder.RetailerList.fillData(RetailerList.java:34)
E/AndroidRuntime(  208):    ... 25 more

Thanks


I think your 'biofuelsDB' is still null!


Add this line after Arrayadapter:

ListView lv;
lv.setAdapter(items); 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号