android - 使用java类的startActivity

时间:2015-02-24 06:21:49

标签: java android

我在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

我已经测试了许多不同的方法来做到这一点,但没有任何效果!有什么帮助吗?

0 个答案:

没有答案