Hi Friends i have written an Activity like below.
SplashScreen.java
public class SplashScreen extends Activity {
protected final int _splashTime = 4000;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
new Handler().postDelayed(new Runnable() {
public void run() {
startActivity(mainIntent);*/
Main mainObj=new Main();
final Bundle bundle=new Bundle();
mainObj.onCreate(bundle);
finish();
}
}, _splashTime);
}
}
From the above Activity iam calling Main.java which is as follows.
public class Main extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);//line 1.
setContentView(R.layout.main1);
}
}
In the above Main.java in the line 1 while calling super.onCreate(savedInstanceState) iam getting NullPointerException.I have identified that if i call the Activity by creating an object using new operator it is giving NullPointerException like below
Main mainObj=new Main();
final Bundle bundle=new Bundle();
mainObj.onCreate(bundle);
But if i call an Activity using
startActivity(new Intent(SplashScreen.this,Main.claass));
iam not getting NullPointerException.So how can i run an Activity by creating an object using new opertor with out NullPointerException.
You should never attempt to create an instance of an
Activityusingnew. This is not how Android works. TheActivityclass is a special case in Android (along with several other special Android components) and you need to create and manage them correctly.To create a new
Activityyou must always create a newIntentand usestartActivity(...)or one of the otherstartActivityXXX(...)methods.See Application Fundamentals