I have a sample app which creates a database, table and inserts a row of values.
Here is my MainActivity.java:
public class MainActivity extends Activity {
protected static final android.content.Context Context = null;
public String ReadingMode="";
@Override
protected void onCreate(Bundle savedInstanceState) {
SQLiteDatabase sampleDB = Context.openOrCreateDatabase("WaterElectricityReading", MODE_WORLD_READABLE, null);
sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +
"SampleTable " +
" (LastName VARCHAR, FirstName VARCHAR," +
" Country VARCHAR, Age INT(3));");
sampleDB.execSQL("INSERT INTO " +
"SampleTable " +
" Values ('Makam','sample','India',25);");
sampleDB.close();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
When I debug line by line, Null pointer exception is raised near the line:
SQLiteDatabase sampleDB = Context.openOrCreateDatabase("WaterElectricityReading", MODE_WORLD_READABLE, null);
I see that sampleDB is null and Database is not being created.
Is any thing wrong with my code?