Update语句返回null

时间:2018-01-04 18:05:49

标签: java android sqlite

当我尝试更新时,我继续获取空指针异常。我曾试图烘烤这些值,而它根本不是null。我被困在这里,任何帮助都会很棒。

01-05 01:50:20.082 31956-31956/org.gandroid.motif E/AndroidRuntime: FATAL EXCEPTION: main
                                                                    Process: org.gandroid.motif, PID: 31956
                                                                    java.lang.NullPointerException
                                                                        at org.gandroid.motif.Secondwcscreen$1.onClick(Secondwcscreen.java:218)
                                                                        at android.view.View.performClick(View.java:4463)
                                                                        at android.view.View$PerformClick.run(View.java:18770)
                                                                        at android.os.Handler.handleCallback(Handler.java:808)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:103)
                                                                        at android.os.Looper.loop(Looper.java:193)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5292)
                                                                        at java.lang.reflect.Method.invokeNative(Native Method)
                                                                        at java.lang.reflect.Method.invoke(Method.java:515)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
                                                                        at dalvik.system.NativeStart.main(Native Method)

这是我尝试更新时遇到的错误。

Bundle b = getIntent().getExtras();
                            getLastperiod = b.getString("LP");
                            Date inputdate = sdf.parse(inputlastperiod);

                            Date getprevdate = sdf.parse(getLastperiod);
                            newcal.setTime(getprevdate);

                            String prevperiod = sdf.format(newcal.getTime());
                            String newperiod = sdf.format(inputdate);


                            Date PP = null;
                            Date NP = null;
                            Integer daysbetween = 0;
                            try {
                                PP = format.parse(prevperiod);
                                NP = format.parse(newperiod);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }

                            DateTime valPP = new DateTime(PP);
                            DateTime valNP = new DateTime(NP);

                            daysbetween = Days.daysBetween(valPP, valNP).getDays();
                            String newPeriodrange=daysbetween.toString();
                            Integer id = 1;



                            if (newPeriodrange!=null) {
                               myDB.updatePeriodrange(newPeriodrange,id);

                           }

这是我的更新声明所在。

public void updatePeriodrange(String newcyclerange,int id){
        SQLiteDatabase dbase = this.getWritableDatabase();
        String query = "UPDATE userinfo SET PERIODRANGE= "+newcyclerange+" WHERE ID='"+id+"'";

        dbase.execSQL(query);
    }

然后这是我的databasehelper类。

0 个答案:

没有答案