Android:这是将数据插入到具有图像的sqlite数据库的代码

时间:2016-01-30 08:55:32

标签: android

//添加访客详情

btnIn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        //TestAdapter testAdapter=new TestAdapter(null);
                        //Cursor c=testAdapter.getData();
                          //insert Visitor name
                         String vname=edit3.getText().toString();
                        Log.w("vname", "abc");

                        /** Receiving the data from previous activity
                         **/
                        //Intent intent=getIntent();
                        //insert Visitor photo
                        Bundle gotimage1=getIntent().getExtras();
                        byte[] img1=gotimage1.getByteArray("key1");
                        Log.w("img1", "got visitor image");
                        //insert Vehicle photo
                        Bundle gotimage2=getIntent().getExtras();
                        byte[] img2=gotimage2.getByteArray("key2");
                        Log.w("img2", "got vehicle image");
                        //insert vehicle number
                        String vNo=edit1.getText().toString();
                        Log.w("vNo", "v1");
                        //insert flat number
                        String fNo=edit2.getText().toString();
                        Log.w("fNo", "f2");

                        long i=testAdapter.insertVisitorData(vname,img1 , img2, vNo, fNo);
                        //Log.e("Visitor","visitor"+vNo);
                        //Log.e("flat no","flatno"+fNo);
                        Log.e("Insertvalue","insertvalue"+i);
                        Toast.makeText(getApplicationContext(), "Record Inserted..."+i+"",Toast.LENGTH_LONG).show();
                    }
                });

上面的代码是使用sqlite将包含图像的数据插入数据库。 但无法插入。 / ************ 这显示错误inti logcat如下: / **********************************************

01-30 14:23:59.237: E/AndroidRuntime(929): FATAL EXCEPTION: main
01-30 14:23:59.237: E/AndroidRuntime(929): java.lang.NullPointerException
01-30 14:23:59.237: E/AndroidRuntime(929):  at com.example.newandroidapp.FirstTab$4.onClick(FirstTab.java:177)
01-30 14:23:59.237: E/AndroidRuntime(929):  at android.view.View.performClick(View.java:4191)
01-30 14:23:59.237: E/AndroidRuntime(929):  at android.view.View$PerformClick.run(View.java:17229)
01-30 14:23:59.237: E/AndroidRuntime(929):  at android.os.Handler.handleCallback(Handler.java:615)
01-30 14:23:59.237: E/AndroidRuntime(929):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-30 14:23:59.237: E/AndroidRuntime(929):  at android.os.Looper.loop(Looper.java:137)
01-30 14:23:59.237: E/AndroidRuntime(929):  at android.app.ActivityThread.main(ActivityThread.java:4960)
01-30 14:23:59.237: E/AndroidRuntime(929):  at java.lang.reflect.Method.invokeNative(Native Method)
01-30 14:23:59.237: E/AndroidRuntime(929):  at java.lang.reflect.Method.invoke(Method.java:511)
01-30 14:23:59.237: E/AndroidRuntime(929):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
01-30 14:23:59.237: E/AndroidRuntime(929):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
01-30 14:23:59.237: E/AndroidRuntime(929):  at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案