我是android开发的新手。我想在public IEnumerable<ViewModel> BuildModel(
Expression<Func<ReportRecord, bool>> predicate)
{
IEnumerable<ReportPart> items = GetList<ReportPart, ReportRecord>(predicate);
}
中插入json string
并收到错误:
Sqlite database
这是我的代码:
DbAdapter.java
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1212, result=0, data=null} to activity : java.lang.NullPointerException.
MainActivity.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");
}
这里我的json String :: 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);
}
}
我在这行中收到错误{"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"}
:
databaseadapter.insertJSONFeedback(JSON, fullName_et.getText()。toString(),email_et.getText()。toString());
提前谢谢。
答案 0 :(得分:1)
因为看起来你的“databaseadapter”对象是对null的引用。因此它会抛出nullpointerexception ....
做一件事并检查它是否崩溃...添加行databaseadapter = new DbAdapter(this); databaseadapter = databaseadapter.open();在onActivityResult()...
答案 1 :(得分:0)
您的活动setContentView(int resId)
错过了onCreate()
。