title: getting error when connecting database in android
body: <pre><code>I am trying to connect the sqlite database with android. I hereby paste the code,
  
  webview.java,
  
  
  public class webview extends Activity{
  EditText ediValue ;
  TextView txt;
   DatabaseHandler db;
  public void onCreate(Bundle savedInstance)
  {
  
      super.onCreate(savedInstance);
      setContentView(R.layout.activity_main);
      btn.setOnClickListener(new View.OnClickListener() {
  
  
      public void onClick(View v) {
          SharedPreferences.Editor editor =     
                                       getPreferences(MODE_PRIVATE).edit();
           editor.putString("text", ediValue.getText().toString());
           editor.putInt("selection-start", ediValue.getSelectionStart());
           editor.putInt("selection-end", ediValue.getSelectionEnd());
           editor.commit();
           String data = getPreferences(MODE_PRIVATE).getString("text","");
           Login login = new Login();
           login.setName(data);
           login.setScore(10);
  
           db.addScore(login);
  
      }
  });
      }
  
  
  }
  </code></pre>
  
  <p>My Login.java is,</p>
  
  <pre><code>public class Login {
  
   public String name;
   public int score;
   public String getName(){
       return name;
   }
   public int getScore(){
       return score;
   }
   public void setScore(int s){
       score=s;
   }
   public void setName(String name){
       this.name = name;
   }
  }
  </code></pre>
  
  <p>And my Databasehandler.java is,</p>
  
  <pre><code>public class DatabaseHandler extends SQLiteOpenHelper {
  
  private static final int DATABASE_VERSION = 1;
  private static final String DATABASE_NAME = "ScoreData ";
  private static final String TABLE_SCORE = "score";
  private static final String KEY_SCORE = "score";
  private static final String KEY_NAME = "name";
  
   public DatabaseHandler(Context context) {
     super(context, null, null, DATABASE_VERSION);
     }
    public void onCreate(SQLiteDatabase db) {
  
     String CREATE_SCORE_TABLE="CREATE TABLE " + TABLE_SCORE +"(" + KEY_NAME + " TEXT," + 
               KEY_SCORE+" INTEGER" + ")";
     db.execSQL(CREATE_SCORE_TABLE);
     }
     public void onUpgrade(SQLiteDatabase db, int oldversion, int newversion) {
      db.execSQL("DROP TABLE IF EXISTS " + TABLE_SCORE);
         onCreate(db);
     }
  
  
     public void addScore(Login login) {
      SQLiteDatabase db = this.getWritableDatabase();
      ContentValues values = new ContentValues();
      values.put(KEY_SCORE, login.getScore());
      values.put(KEY_NAME, login.getName());
      db.insert(TABLE_SCORE, null, values);
      db.close();
     }
     }
  </code></pre>
  
  <p>And now i am getting nullpointerexception, when i run this activity. Can anyone tell what is wrong in this code. I use android 4.2. Apart from the code, i did not do any changes in db side. I hereby post the exception,</p>
  
  <pre><code>05-02 09:00:44.635: E/Trace(1033): error opening trace file: No such file or directory (2)
  05-02 09:00:44.875: E/AndroidRuntime(1033): FATAL EXCEPTION: main
  05-02 09:00:44.875: E/AndroidRuntime(1033): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.newandroid/com.example.newandroid.webview}: java.lang.NullPointerException
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at android.os.Handler.dispatchMessage(Handler.java:99)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at android.os.Looper.loop(Looper.java:137)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at android.app.ActivityThread.main(ActivityThread.java:5041)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at java.lang.reflect.Method.invokeNative(Native Method)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at java.lang.reflect.Method.invoke(Method.java:511)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at dalvik.system.NativeStart.main(Native Method)
  05-02 09:00:44.875: E/AndroidRuntime(1033): Caused by: java.lang.NullPointerException
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:109)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at com.example.newandroid.webview.&lt;init&gt;(webview.java:17)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at java.lang.Class.newInstanceImpl(Native Method)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at java.lang.Class.newInstance(Class.java:1319)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
  05-02 09:00:44.875: E/AndroidRuntime(1033):     ... 11 more
  05-02 09:03:42.775: E/AndroidRuntime(1414): FATAL EXCEPTION: main
  </code></pre>