数据库错误:尝试在空对象引用

时间:2017-01-18 07:45:27

标签: android sqlite nullpointerexception android-sqlite

  

java.lang.NullPointerException:尝试调用虚方法   “android.database.Cursor   com.example.munna.homeauto.DatabaseCreation.getScene()'在null上   对象参考

public class Server extends Activity {

    DatabaseCreation myDb;
    int i;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.scenario);

        myDb = new DatabaseCreation(this);

    }

    public void server_check() {
        System.out.println("client");
        int j;
        int k;
        Cursor scene = myDb.getScene();//unfortunetly stops when cursor comes to this step
        while (scene.moveToNext()) {
            System.out.println("client 1");
            for (i = 0; i <= 5; i++) {
                scene.getString(i);
                System.out.println("client 2");
                // my code for server message 
            }

        }

    }
}

1 个答案:

答案 0 :(得分:0)

library(data.table)
res1 <- setDT(df1)[, c('time1', 'time2') := tstrsplit(timeinterval, " ")
     ][, if(all(timecount!=0)) .(timeinterval= paste(time1[1], time2[.N]), timecount = .N),
          .(grp = rleid(timecount))][, grp := NULL][]
res1
#        timeinterval timecount
#1: 00:00:00 02:59:59         3
#2: 08:00:00 09:59:59         2
#3: 14:00:00 14:59:59         1
#4: 19:00:00 19:59:59         1
#5: 21:00:00 23:59:59         3

祝你好运:)