Getting Context from other class causing NPE
I'm trying to call a new activity in non-activity class using this codes:
Intent usage = new Intent(UsageActivity.getContext(),UsageActivity.class);
usage.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
UsageActivity.getContext().startActivity(usage);
and I have a UsageActivity that has this codes:
public static Context mContext;
below the onCreate()
mContext = getBaseContext();
i created a method like this:
public static Context getContext() {
return mContext;
}
It throws an exception saying this:
04-25 17:30:00.485: W/System.err(6518): java.lang.NullPointerException
04-25 17:30:00.501: W/System.err(6518): at
android.content.ComponentName.<init>(ComponentName.java:75)
04-25 17:30:00.501: W/System.err(6518): at
android.content.Intent.<init>(Intent.java:2823)
04-25 17:30:00.501: W/System.err(6518): at
com.itaxeeta.server.Search.onPostExecute(Search.java:219)
Does my way of creating a context was wrong? any thoghts will be highly
appreciated.
No comments:
Post a Comment