0
爲什麼我得到這樣的錯誤?我想在textview和toast上顯示我的sqlite列Fat的總和,以便我知道它正在運行,但出現錯誤。獲取sqlite列錯誤的總和
android.content.res.Resources$NotFoundException: String resource ID
#0x7b
at android.content.res.Resources.getText(Resources.java:299)
at android.support.v7.widget.ResourcesWrapper.getText(ResourcesWrapper.java:52)
at android.widget.TextView.setText(TextView.java:4132)
at jm.myapplication.Main.MainActivity.totalFat(MainActivity.java:169)
at jm.myapplication.Main.MainActivity.onClick(MainActivity.java:498)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
此代碼是在我的MainActivity類別
public void totalFat()
{
repo repo = new repo(MainActivity.this);
int i = repo.totalFatrepo();
tvtotal.setText(i);
Toast.makeText(getApplicationContext(),
i, Toast.LENGTH_LONG)
.show();
}
@Override
public void onClick(View view) {
if (view == findViewById(R.id.water)) {
totalFat();
}
}
,而這是在我的回購
public int totalFatrepo(){
SQLiteDatabase db = dbHelper.getWritableDatabase();
String query = "SELECT SUM(Fat) FROM " + breakfast.TABLE;
Cursor c = db.rawQuery(query, null);
c.moveToFirst();
int i=c.getInt(0);
return i;
}
謝謝老兄!你真的解決了我的問題:)謝謝 –