我想知道如何從我創建的意圖調用我的數據庫類。當我在intent類中進行調用時,我得到一個空指針異常,就像意圖無法看到外部類......任何想法都非常感謝或指向鏈接?從意圖調用數據庫類
呼籲意圖從郵件類
Intent showContent = new Intent(context, IntentResults.class);
Log.d(LOG_TAG, "About to launch sub-activity");
// Set the request code to any code you like, you can identify the
// callback via this code
startActivityForResult(showContent, 0);
Log.d(LOG_TAG, "launched sub-activity");
然後我打電話的意圖類將包括DB類。 AABDatabaseManager db = new AABDatabaseManager(this); 公共類IntentResults延伸活動{
private static final String LOG_TAG = "IntentResultsClass";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.intentayanlsisdatapage);
Log.d(LOG_TAG, "in sub-activity");
Log.d(LOG_TAG, "finish should have run");
int NumOfEntries = db.countNumberOfEntries();
String numberOfEntries = ""+NumOfEntries;
我得到一個空指針在這裏
int NumOfEntries = db.countNumberOfEntries()
爲doesent DB類似乎得到貫徹。我一直在尋找:
External AsyncTask class with ProgressDialog [Update: and returning back?]
但figureing爲什麼當我從意圖調用DB類是不想要工作對我來說沒有快樂,任何幫助非常appriceated。
只是爲了增加更多的細節:
11-30 12:42:09.199: WARN/dalvikvm(31304): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): FATAL EXCEPTION: main
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{test3.patrickrice.net/test3.patrickrice.net.IntentResults}: java.lang.NullPointerException
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at android.os.Handler.dispatchMessage(Handler.java:99)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at android.os.Looper.loop(Looper.java:123)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at java.lang.reflect.Method.invokeNative(Native Method)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at java.lang.reflect.Method.invoke(Method.java:521)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at dalvik.system.NativeStart.main(Native Method)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): Caused by: java.lang.NullPointerException
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at test3.patrickrice.net.AABDatabaseManager.<init>(AABDatabaseManager.java:65)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at test3.patrickrice.net.IntentResults.<init>(IntentResults.java:17)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at java.lang.Class.newInstanceImpl(Native Method)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at java.lang.Class.newInstance(Class.java:1429)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
11-30 12:42:09.311: ERROR/AndroidRuntime(31304): ... 11 more
11-30 12:42:09.389: WARN/ActivityManager(59): Force finishing activity test3.patrickrice.net/.IntentResults
11-30 12:42:09.889: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{45147568 test3.patrickrice.net/.IntentResults}
11-30 12:42:19.395: WARN/ActivityManager(59): Launch timeout has expired, giving up wake lock!
感謝 帕特
刪除了finishe並創建了db = new AABDatabaseManage(),但仍然沒有快樂。 – pat
NPE看起來像它在AABDatabaseManage() – JonWells