我在java类中启动活动时遇到问题,我想从java类中激活一个活动我尝试了这段代码,但它没有工作:
public class AlMA_PRO_Class{
public static void Start_Setting(){
ActionBarActivity mn = new MainActivity2(); // this is the setting activity
//i've tried it like this way ==> mn.setContentView(R.layout.activity_main_activity2);
//but not working , so i've tried this code below
Bundle b = new Bundle();
b.putString("command","not used , just because it's needed");
startActivity(new Activity(), new Intent(new Activity(),MainActivity2.class), b);
}
}
并返回以下错误:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
我已经测试了许多不同的方法来做到这一点,但没有任何效果!有什么帮助吗?