2013-01-05 74 views
0

在我的應用程序的某處。我需要從一個方法返回ContentValues。但似乎我不能這樣做,或者有一些我在執行時錯過了。當我想將這個返回值傳遞給另一個類方法時,它會因爲nullPointerException而崩潰。返回ContentValues

這是我調用返回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(); 
    } 

回答

1

看起來你忘了初始化testContentValues

testContentValues = new ContentValues();