2015-06-10 47 views
0

我在android系統development..I是新希望插入Sqlite databasejson string和獲取錯誤:安卓:數據可仍然得到錯誤NullPointerException異常

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1212, result=0, data=null} to activity : java.lang.NullPointerException. 

這裏是我的代碼:

DbAdapter.java

static final String DATABASE_FEEDBACK="CREATE TABLE IF NOT EXISTS "+" feedbackjson "+ 
     "("+"FeedbackId"+" integer primary key autoincrement, "+" JSON text, Fullname text, Email text, AdminId text);"; 


public void insertJSONFeedback(String json,String fullName,String email) 
{ 
    Log.i("Data Insert reached", "yes"); 

    ContentValues newValues = new ContentValues(); 
    Log.i("JSON STRING to be insert1",json); 
    newValues.put("JSON", json); 
    newValues.put("Fullname",fullName); 
    newValues.put("Email",email); 
    newValues.put("AdminId","1"); 
    db.insert("feedbackjson", null, newValues); 
    Toast.makeText(context, "Data Is Successfully Saved", Toast.LENGTH_LONG).show(); 
    Log.i("context", "Toast"); 

} 

MainActivity.java:

public class MainActivity extends ActionBarActivity { 
DbAdapter databaseadapter; 

    @Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    databaseadapter=new DbAdapter (this); 
    databaseadapter=databaseadapter.open(); 
} 


@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

    super.onActivityResult(requestCode, resultCode, data); 
    Log.i("Result Code", resultCode + ""); 


    fullName_et=(EditText) findViewById(R.id.name_et); 
    email_et=(EditText) findViewById(R.id.email_et); 

    String detailInformation = ""; 
    LinkedHashMap<String, String> userFields = new LinkedHashMap<String, String>(); 
    userFields = UtilityClass.EDIT_PROFILE_WITH_FIELD_NAME; 

    String fieldValueAndPrivacy = null;// = new 

    Gson gson = new Gson(); 
    String json = gson.toJson(userFields, LinkedHashMap.class); 

    Log.i("User Fields",json); 

    databaseadapter.insertJSONFeedback(json, fullName_et.getText().toString(), email_et.getText().toString()); 

    LinkedHashMap<String, ArrayList<String>> editProfileHashValues = new LinkedHashMap<String, ArrayList<String>>(); 

    Iterator fieldIterator = userFields.entrySet().iterator(); 
    while (fieldIterator.hasNext()) { 
     Map.Entry fieldPairs = (Map.Entry) fieldIterator.next(); 
     String fieldName = (String) fieldPairs.getKey(); 
     String fieldRunTimeValue = (String) fieldPairs.getValue(); 
     detailInformation += fieldName + " => " + fieldRunTimeValue 
       + "\n"; 
     Log.i("Detail Information", detailInformation); 
    } 
} 

這裏我的JSON字符串:: {"Full Name":"gyt","Email Address":"ggfh","Contact Number":"987654568","Rate Quality of Food":"2.5","Service Quality":"3.0","Overall Experience":"3.0","Restaurant Branch":"Vadodara","Comments":"okh"}

,我在這行有錯誤java.lang.NullPointerException

databaseadapter.insertJSONFeedback(JSON, fullName_et.getText()的toString(),email_et.getText。 ()的ToString());

在此先感謝您。

+0

使用調試器找出最終值爲空。 – Jens

+0

沒有任何值是空的...我已經檢查過...仍然geting錯誤nullpointerexception ..是否有任何其他原因?不使用數據庫在活動結果或任何其他... – Ammy

+0

添加完整的LogCat – Jens

回答

1

,因爲它似乎你的「databaseadapter」對象引用null..hence它拋出NullPointerException異常....

做一兩件事,並檢查它崩潰或不...添加這兩個線databaseadapter =新DbAdapter(this); databaseadapter = databaseadapter.open();在onActivityResult()...

0

你錯過了setContentView(int resId)onCreate()你的活動。

+0

我沒有寫在這裏的整個代碼...它已經在我的代碼中可用,但不能寫在這裏整個頁面代碼..只有相關的數據被寫入 – Ammy

+0

@Ammy把你的完整的Logcat。 –

相關問題