从sqlite数据库中的数据填充复选框时出错

时间:2014-02-09 17:12:05

标签: android checkbox android-listview cursor android-sqlite

我正在填充一个包含复选框和按钮的列表视图,列表视图将从数据库中填充。

对我来说,Eve​​rthing工作正常,直到我尝试将数据库中的行值设置为复选框的文本,搜索并实现但无法将数据库中的值填充到复选框文本。

下面是我的代码:这里我只回溯一个有大约10条记录的列值

public class stockmanager extends Activity{

    /*public stockmanager() {
        // TODO Auto-generated constructor stub
        populatelist pl=new populatelist();
        //pl.getView(position, getCurrentFocus(), null);
    }*/
    String getentry;
    private int storeID=0;
    Database d;
    StockTable st;  
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.stockmanager);
        d=new Database(getApplicationContext());
        st=new StockTable(getApplicationContext());
    final Button AddStock=(Button) findViewById(R.id.button1);
         final EditText entry=(EditText) findViewById(R.id.editText1);
        final Button BroDetail=(Button) findViewById(R.id.button2);
        final ListView popstocks=(ListView) findViewById(R.id.listView1);

        AddStock.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                getentry=entry.getText().toString();
                //st.insert(getentry);
                System.out.println(getentry);
                //d.db.rawQuery(st.select(), null);
                d.db.insert(st.tablename, null,st.insert(getentry));
                populatelist populatestocks=new populatelist();
                popstocks.setAdapter(populatestocks);

            }
        });
                }


    public class populatelist extends BaseAdapter{

        StockTable st1=new StockTable(getApplicationContext());
        Database d1=new Database(getApplicationContext());
        private String getstocks="Select "+ st1.column2 + " From "+ st1.tablename;
        private Cursor a1;
        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            a1=d.db.rawQuery(getstocks, null);
            return a1.getCount();
        }

        @Override
        public Object getItem(int arg0) {
            // TODO Auto-generated method stub
            return arg0;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            if(convertView==null){

                convertView=getLayoutInflater().inflate(R.layout.stocklist,null);
            }

            final CheckBox cb=(CheckBox) findViewById(R.id.checkBox1);
            final Button view=(Button) findViewById(R.id.button1); 


            if(a1.moveToFirst()){

            cb.setText(a1.getString(a1.getColumnIndex(st1.column2)));
            *****above statement is generating error******

            }
            return convertView;
        }


    }

    public void Declerations(){


    }


}

记录猫

02-09 17:02:28.391: D/libEGL(19478): loaded /system/lib/egl/libEGL_genymotion.so
02-09 17:02:28.455: D/(19478): HostConnection::get() New Host Connection established 0xb8ad4fc8, tid 19478
02-09 17:02:28.499: D/libEGL(19478): loaded /system/lib/egl/libGLESv1_CM_genymotion.so
02-09 17:02:28.523: D/libEGL(19478): loaded /system/lib/egl/libGLESv2_genymotion.so
02-09 17:02:28.927: W/EGL_genymotion(19478): eglSurfaceAttrib not implemented
02-09 17:02:28.959: E/OpenGLRenderer(19478): Getting MAX_TEXTURE_SIZE from GradienCache
02-09 17:02:29.011: E/OpenGLRenderer(19478): Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
02-09 17:02:29.011: D/OpenGLRenderer(19478): Enabling debug mode 0
02-09 17:02:34.215: W/EGL_genymotion(19478): eglSurfaceAttrib not implemented
02-09 17:02:40.079: D/dalvikvm(19478): GC_FOR_ALLOC freed 105K, 1% free 16944K/17072K, paused 73ms, total 76ms
02-09 17:02:40.331: W/EGL_genymotion(19478): eglSurfaceAttrib not implemented
02-09 17:02:40.631: I/System.out(19478): sdef
02-09 17:02:40.631: I/System.out(19478): Select Max(Stock_ID) from StockTable
02-09 17:02:40.647: I/System.out(19478): 1
02-09 17:02:40.727: I/System.out(19478): Has Values
02-09 17:02:41.271: D/AndroidRuntime(19478): Shutting down VM
02-09 17:02:41.295: W/dalvikvm(19478): threadid=1: thread exiting with uncaught exception (group=0xa4c44648)
02-09 17:02:41.359: E/AndroidRuntime(19478): FATAL EXCEPTION: main
02-09 17:02:41.359: E/AndroidRuntime(19478): java.lang.NullPointerException
02-09 17:02:41.359: E/AndroidRuntime(19478):    at com.example.portfoliomanager.stockmanager$populatelist.getView(stockmanager.java:96)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.widget.AbsListView.obtainView(AbsListView.java:2177)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.widget.ListView.makeAndAddView(ListView.java:1840)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.widget.ListView.fillDown(ListView.java:675)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.widget.ListView.fillFromTop(ListView.java:736)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.widget.ListView.layoutChildren(ListView.java:1655)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.widget.AbsListView.onLayout(AbsListView.java:2012)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.View.layout(View.java:14289)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.View.layout(View.java:14289)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.View.layout(View.java:14289)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.View.layout(View.java:14289)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.View.layout(View.java:14289)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.Choreographer.doFrame(Choreographer.java:532)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.os.Handler.handleCallback(Handler.java:730)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.os.Handler.dispatchMessage(Handler.java:92)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.os.Looper.loop(Looper.java:137)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at android.app.ActivityThread.main(ActivityThread.java:5103)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at java.lang.reflect.Method.invokeNative(Native Method)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at java.lang.reflect.Method.invoke(Method.java:525)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-09 17:02:41.359: E/AndroidRuntime(19478):    at dalvik.system.NativeStart.main(Native Method)
02-09 17:02:46.431: I/Process(19478): Sending signal. PID: 19478 SIG: 9
02-09 17:02:49.055: D/libEGL(19514): loaded /system/lib/egl/libEGL_genymotion.so
02-09 17:02:49.079: D/(19514): HostConnection::get() New Host Connection established 0xb8ad4d00, tid 19514
02-09 17:02:49.187: D/libEGL(19514): loaded /system/lib/egl/libGLESv1_CM_genymotion.so
02-09 17:02:49.191: D/libEGL(19514): loaded /system/lib/egl/libGLESv2_genymotion.so
02-09 17:02:49.483: W/EGL_genymotion(19514): eglSurfaceAttrib not implemented
02-09 17:02:49.515: E/OpenGLRenderer(19514): Getting MAX_TEXTURE_SIZE from GradienCache
02-09 17:02:49.599: E/OpenGLRenderer(19514): Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
02-09 17:02:49.599: D/OpenGLRenderer(19514): Enabling debug mode 0

请建议我出路。

由于 希瓦

0 个答案:

没有答案