我有SDcard数据库文件和app sqlite数据库如何比较大小?当我在下面运行此代码时,总是崩溃..
private ContextWrapper context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
File extStore = Environment.getExternalStorageDirectory();
File myFile = new File(extStore.getAbsolutePath() + externalPath
+ FileName);
File f = context.getDatabasePath(DB_PATH);
long dbSize = f.length();
if (dbSize <= myFile.length()) {
//code here
} else {
}
感谢您的帮助...
05-18 02:33:05.410: E/AndroidRuntime(1085): FATAL EXCEPTION: main
05-18 02:33:05.410: E/AndroidRuntime(1085): Process: in.wptrafficanalyzer.searchdialogdemo, PID: 1085
05-18 02:33:05.410: E/AndroidRuntime(1085): java.lang.RuntimeException: Unable to start activity ComponentInfo{in.wptrafficanalyzer.searchdialogdemo/in.wptrafficanalyzer.searchdialogdemo.Lite Activity}: java.lang.NullPointerException
05-18 02:33:05.410: E/AndroidRuntime(1085): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-18 02:33:05.410: E/AndroidRuntime(1085): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-18 02:33:05.410: E/AndroidRuntime(1085): Caused by: java.lang.NullPointerException
05-18 02:33:05.410: E/AndroidRuntime(1085): at in.wptrafficanalyzer.searchdialogdemo.LiteActivity.onCreate(LiteActivity.java:65)
05-18 02:33:05.410: E/AndroidRuntime(1085): at android.app.Activity.performCreate(Activity.java:5231)
05-18 02:33:05.410: E/AndroidRuntime(1085): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-18 02:33:05.410: E/AndroidRuntime(1085): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-18 02:33:05.410: E/AndroidRuntime(1085): ... 11 more
答案 0 :(得分:0)
您的context
为空,因为您尚未初始化它。
由于您正在运行某个活动的方法,因此将Context
存储为成员变量毫无意义。请改用this
。取代
context.getDatabasePath(DB_PATH);
只是
getDatabasePath(DB_PATH);