i dont know how far i am right, but doesn't the context change when u
instantiate a new activity object?
>myact maobj=new myact();
hence the exception.
jus move the code in open() to the line after dbhelper instatiation. it
should work fine. there is no need to create a new activity object.

On Wed, Aug 5, 2009 at 5:02 PM, saptarshi chatterjee <
[email protected]> wrote:

>
> Friends,
>
> In the following code the method  "public void open() throws
> SQLException " is throwing NullPointeeException. Please help me.
>
> Thanks & Regards
> Saptarshi
>
>
>
> package com.outp.inp;
>
>
> import android.app.Activity;
> import android.content.Context;
> import android.database.Cursor;
> import android.database.SQLException;
> import android.database.sqlite.SQLiteDatabase;
> import android.database.sqlite.SQLiteOpenHelper;
> import android.os.Bundle;
> import android.util.Log;
> import android.widget.Toast;
>
>
> public class myact extends Activity {
>
>
>        public static final String KEY_ROWID = "_id";
>    public static final String KEY_VEHICLE = "vehicle";
>    public static final String KEY_ROUTE = "route";
>    public static final String KEY_COUNTRY = "country";
>    public static final String KEY_CITY = "city";
>    private static final String TAG = "DBAdapter";
>
>    private static final String DATABASE_NAME = "publicTransport";
>    private static final String DATABASE_TABLE = "vehicleTable";
>    private static final int DATABASE_VERSION = 1;
>
>    long id;
>    Cursor c;
>
>    private static final String DATABASE_CREATE =
>        "create table vehicleTable (_id integer primary key
> autoincrement, "
>        + "vehicle text not null, route text not null, "
>        + "country text not null,city text not null);";
>
>
>    private  final Context context=this;
>    private DatabaseHelper DBHelper;
>    private SQLiteDatabase sqlitedatabase;
>
>
>
>
>
>
>
>
>    /** Called when the activity is first created. */
>    @Override
>    public void onCreate(Bundle savedInstanceState) {
>        super.onCreate(savedInstanceState);
>        setContentView(R.layout.main);
>
>        DBHelper = new DatabaseHelper(context);
>        myact maobj=new myact();
>        try{
>        maobj.open();}
>        catch(Exception e){Toast.makeText(this, "misfunctioning
> open"+e.toString(),Toast.LENGTH_LONG).show();}
>
>
>    }
>
>
>
>    private static class DatabaseHelper extends SQLiteOpenHelper
>    {
>        DatabaseHelper(Context context)
>        {
>            super(context, DATABASE_NAME, null, DATABASE_VERSION);
>
>        }
>
>
>        public void onCreate(SQLiteDatabase db)
>        {
>
>            db.execSQL(DATABASE_CREATE);
>
>
>        }
>
>        @Override
>        public void onUpgrade(SQLiteDatabase db, int oldVersion,
>                              int newVersion)
>        {
>            Log.w(TAG, "Upgrading database from version " +
> oldVersion
>                  + " to "
>                  + newVersion + ", which will destroy all old data");
>            db.execSQL("DROP TABLE IF EXISTS titles");
>            onCreate(db);
>        }
>    }
>
>
>
>
>    public void open() throws SQLException
>    {
>
>        sqlitedatabase = DBHelper.getWritableDatabase();
>     }
>
>
>  }
>
>
>
>
>
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to