0

I have got SDcard database file and app sqlite database how do i compare the size? when i run this code below, always crashing..

   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 {



    }

appreciate your help…

 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
user1710911
  • 657
  • 3
  • 7
  • 15

1 Answers1

0

Your context is null as you have not initialized it.

Since you're running in a method of an activity, there's no point really storing a Context as a member variable. Use this instead. Replace

context.getDatabasePath(DB_PATH);

with just

getDatabasePath(DB_PATH);
laalto
  • 150,114
  • 66
  • 286
  • 303