ClassCast exception in case of loading class from other andoid project

by Megha Joshi » Wed, 14 May 2008 18:39:08 GMT


Sponsored Links
 Hi,

Please see the solution in the thread below and let us know if that works
for you.



Other Threads

1. Access database (in static method?) in non-Activity class

I have some class (SomeClass.class). I want to have some static
methods in it like getAllDatabaseItems, getTableItems, insertNewRecord
and so on.

If I do it this way

        SQLiteDatabase db = openOrCreateDatabase(DATABASE_NAME,
MODE_PRIVATE, null);

I need to extend Activity (but still can't use it in static methods)
or pass a "db" variable in every single method (from "caller
activity") which is pretty bulky.

What's the solution so I can from some class call
SomeClass.getAllDatabaseItems()? In short I have two classes, I have
main activity/class (which displays UI and so on) and
DatabaseOptions.java class which I should call anytime I need to (from
any other activities as well) to manipulate with my database.

User @MobileDev123 suggested me to use Context but I'm still not
getting it right...even this code isn't working.

public class Partner extends Activity {
@SuppressWarnings("static-access")
public Partner(Context mContext) {
    myContext = mContext;
    db = openOrCreateDatabase(DATABASE_NAME, myContext.MODE_PRIVATE,
null);

    db.execSQL("CREATE TABLE IF NOT EXISTS " + PARTNER_TABLE_NAME +
" (id INTEGER PRIMARY KEY AUTOINCREMENT, " + NAME + " VARCHAR);");
    db.execSQL("CREATE TABLE IF NOT EXISTS " + ADDRESS_TABLE_NAME +
" (id INTEGER PRIMARY KEY AUTOINCREMENT, " + PARTNER_ID + " INT, " +
ADDRESS + " VARCHAR, " + CITY + " VARCHAR);");
}

And then call it from some of my activites like this

    Partner newPartner = new Partner(this);
    partnersItems = newPartner.getAllItems();

I get an NullExceptionError on line 4 (Partner.class) - why? If I use
static reference on

MODE_PRIVATE --> (Context.MODE_PRIVATE)

again it's not working.

-- 

2. Android proximity messaging

How do I send messages from one android to another android phone
within close proximity? For example, Is it possible for a nearby phone
to receive requests to open a webpage from another phone? Of course,
only if the phone is willing to accept it. Does the API support this
functionality?

-- 

3. Running two Activities in Android Project

4. Licensing an Application : Android Library Projects cannot be Launched.

5. android 2.1 using usb bluetooth

6. How to creating Launcher "home screen" behavior on my app?

7. How to view the logs when USB dubug is disabled?