0

在我的应用程序的某个地方。我需要从方法返回 ContentValues。但似乎我做不到,或者在实现它时我错过了一些东西。当我想将此返回值传递给另一个类方法时,它会因为 nullPointerException 而崩溃。

这是我调用返回 ContentValues 方法并将其传递给其他方法的地方:

new Thread(new Runnable() {
            public void run() {
                try{
                    Thread.sleep(3000);
                    generateFeatures gen=new generateFeatures(getBaseContext());
                    ContentValues ourContentValues=gen.letsRollOut(); //calling the method that returns smth. type ContentValues 
                    makeDesicion md=new makeDesicion(ourContentValues,getBaseContext());
                    md.controlWithDB();
                    md.finalDesicion();
                    db.delete("Koordinatlar", null, null);
                    }
                    catch(InterruptedException ex){
                        ex.printStackTrace();
                    }

            }
          }).start();

返回 ContentValues 的方法:

public ContentValues letsRollOut(){
        boolean bitti=false;

        Cursor firstTimeHandler=db.rawQuery("SELECT MIN(zaman) FROM Koordinatlar", null);
        firstTimeHandler.moveToFirst();

        long firstTime= firstTimeHandler.getLong(0);
        long nextTime=firstTime+3000;

        Cursor lastTimeHandler=db.rawQuery("SELECT MAX(zaman) FROM Koordinatlar", null);
        lastTimeHandler.moveToFirst();

        long lastTime=lastTimeHandler.getLong(0);
        while(!bitti){

            myContentValues.clear();

            calculateAverage(firstTime,nextTime);
            calculateStandartDev(firstTime,nextTime);
            calculateAverageAbsoluteDifferance(firstTime,nextTime);
            calculateAverageResultant(firstTime,nextTime);
            calculateMax(firstTime,nextTime);
            calculateBinnedDist(firstTime,nextTime);

            firstTime=(long) (nextTime+0.00000001);
            nextTime=(nextTime+3000);

            if(nextTime>=lastTime){
                bitti=true;

            }

            myContentValues.put("ortX", averageX);
            myContentValues.put("ortY", averageY);
            myContentValues.put("ortZ", averageZ);
            myContentValues.put("stdX", stdX);
            myContentValues.put("stdY", stdY);
            myContentValues.put("stdZ", stdZ);
            myContentValues.put("aadX", aadX);
            myContentValues.put("aadY", aadY);
            myContentValues.put("aadZ", aadZ);
            myContentValues.put("maxX", maxX);
            myContentValues.put("maxY", maxY);
            myContentValues.put("maxZ", maxZ);
            myContentValues.put("averageResultantAcc", averageResultantAcc);



        }


        return myContentValues;

    }

这是我得到错误的地方。

public makeDesicion(ContentValues ourContentValues,Context con){
        testContentValues.putAll(ourContentValues);  // get nullpointer error in this line.
        ourContext=con;
        veriTabani=new VeriTabani(this.ourContext);
        db=veriTabani.getWritableDatabase();
    }
4

1 回答 1

1

看起来你忘了初始化testContentValues

testContentValues = new ContentValues();
于 2013-01-05T20:20:06.753 回答