我知道我再次提出这个问题,但我在SO和其他网站上尝试了几个解决方案,但没有救援。 虽然我的数据库是通过DDMS视图显示的,但我在尝试获取数据库的可读实例时获取NULL指针异常。 Plz帮助
如果需要其他东西,请告诉我
LOGCAT:
02-28 01:28:56.585: ERROR/NewContactTrackService(285): Adding to instant upload database contact id 21
02-28 01:28:56.595: ERROR/NewContactTrackService(285): Added to instant upload database contact id 21
02-28 01:28:56.615: ERROR/Net UNAVAILABLE details stored in buffer(285): Sd
02-28 01:28:58.186: ERROR/NetworkReceiver(285): onReceive: connected, starting UpdaterService
02-28 01:28:58.186: ERROR/NewContactTrackService(285): UPDATE CALLED
02-28 01:28:58.186: ERROR/NewContactTrackService(285): INSIDE IF
02-28 01:28:58.186: ERROR/NewContactTrackService(285): qqqqqqqqqqqqqqqqqqqqqqqqq
02-28 01:28:58.195: ERROR/AndroidRuntime(285): Uncaught handler: thread main exiting due to uncaught exception
02-28 01:28:58.245: ERROR/AndroidRuntime(285): java.lang.RuntimeException: Unable to start receiver com.gooogle.omcsa.NetworkReceiver: java.lang.NullPointerException
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2646)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at android.app.ActivityThread.access$3100(ActivityThread.java:119)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at android.os.Handler.dispatchMessage(Handler.java:99)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at android.os.Looper.loop(Looper.java:123)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at android.app.ActivityThread.main(ActivityThread.java:4363)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at java.lang.reflect.Method.invokeNative(Native Method)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at java.lang.reflect.Method.invoke(Method.java:521)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at dalvik.system.NativeStart.main(Native Method)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): Caused by: java.lang.NullPointerException
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:193)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:158)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at com.gooogle.omcsa.NewContactTrackService.update(NewContactTrackService.java:185)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at com.gooogle.omcsa.NetworkReceiver.onReceive(NetworkReceiver.java:21)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2637)
02-28 01:28:58.245: ERROR/AndroidRuntime(285): ... 10 more
02-28 01:28:58.275: ERROR/dalvikvm(285): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
02-28 01:28:59.635: ERROR/ActivityThread(52): Failed to find provider info for android.server.checkin
网络接收器
public class NetworkReceiver extends BroadcastReceiver { //
public static final String TAG = "NetworkReceiver";
@Override
public void onReceive(Context context, Intent intent) {
boolean isNetworkDown = intent.getBooleanExtra(
ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
if (isNetworkDown) {
Log.e(TAG, "onReceive: NOT connected, stopping UpdaterService");
//context.stopService(new Intent(context, UpdaterService.class)); //
} else {
Log.e(TAG, "onReceive: connected, starting UpdaterService");
NewContactTrackService networkTrack= new NewContactTrackService();
networkTrack.update();
Log.e(TAG, "onReceive: connected,uploading ");
//context.startService(new Intent(context, UpdaterService.class)); //
}
}
}
NewContactTrackService:为了简化,我只发布了相关的服务部分
public class NewContactTrackService extends Service {
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
dbBuffer = new DbContactBuffer(this);
dbInstantBuffer = new DbInstantBuffer(this);
values = new ContentValues();
instantupload=0;
isInstantUploadEnabled = this.getSharedPreferences("isEnabled", MODE_WORLD_READABLE);
isDataForInstantUpload=false;
Log.e(TAG,"onCreate");
}
public void update()
{
Log.e(TAG,"UPDATE CALLED");
Log.e(TAG,"INSIDE IF");
dbInstantBuffer = new DbInstantBuffer(this);
Log.e(TAG," qqqqqqqqqqqqqqqqqqqqqqqqq");
db1 = dbInstantBuffer.getReadableDatabase(); //THIS IS THE LINE OF EXCEPTION
Log.e(TAG," wwwwwwwwwwwwwwwwwwwwwww");
cursor = db1.query(DbInstantBuffer.TABLE, null, null, null, null, null,null);
//startManagingCursor(cursor);
Log.e(TAG," "+ cursor.getCount());
while (cursor.moveToNext())
{
//SOME CODE
}
db1.close();
}
}
答案 0 :(得分:0)
您可以在onCreate和update方法中定义dbInstantBuffer = new DbInstantBuffer(this);
两次。此外,我没有看到dbInstantBuffer的声明(如何以及在何处定义)。