简体   繁体   English

使用Intent返回时,应用崩溃

[英]App crashes when getting Back using Intent

My application crashed when I'm trying to navigate from one activity to another.I have a menu page which consists of buttons,when i hit the first button it takes me to another activity, but when i am trying to get back to my menu activity i am getting null pointer exceptions.I don't know what is the problem exactly? 当我尝试从一个活动导航到另一个活动时,我的应用程序崩溃了。我有一个包含按钮的菜单页面,当我按下第一个按钮时,它将带我进入另一个活动,但是当我尝试返回菜单时我正在得到空指针异常。我不知道到底是什么问题?

    Intent  intent = new Intent(VehicleNo.this,OptionMenuAct.class);
   startActivity(intent);

I am using the above code to get back to menu page.I am getting problem in oncreate function.this is the code for that 我正在使用上面的代码返回菜单页面。我在oncreate函数中遇到问题。这是该代码

    protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_option_menu);



    t_row1=(TableRow)findViewById(R.id.t_row1);
    t_row2=(TableRow)findViewById(R.id.t_row2);
    t_row3=(TableRow)findViewById(R.id.t_row3);
    t_row4=(TableRow)findViewById(R.id.t_row4);
    t_row5=(TableRow)findViewById(R.id.t_row5);
    t_row6=(TableRow)findViewById(R.id.t_row6);
    t_row7=(TableRow)findViewById(R.id.t_row7);
    t_row8=(TableRow)findViewById(R.id.t_row101);
    t_row9=(TableRow)findViewById(R.id.t_row102);


    ArrayList<String> pv = new ArrayList<String>();

    pv = getIntent().getStringArrayListExtra("values");

    for (String s : pv) 
    {
        Log.d("k", s);
    }

Your OnCreate method uses its intent and it should have an stringarraylist along with it, you are passing no such a thing. 您的OnCreate方法使用了它的意图,并且应该有一个stringarraylist,您没有传递任何东西。 try to pass your desired stringarraylist when you are starting your menu activity 开始菜单活动时尝试传递所需的stringarraylist

如果只想返回菜单页面,则可以调用this.finish()this.finish()当前活动并返回菜单页面活动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM