简体   繁体   English

导航时Android应用程序停止

[英]Android app stops when navigating

I am new to android, my app fails or stops working when I click the navigate button which should direct me to another activity. 我是android的新手,单击导航按钮应将我定向到另一活动时,我的应用程序失败或停止工作。 This is my code to navigate to the next activity. 这是我的代码以导航到下一个活动。

public void checkout(View view) {
      Intent intent = new Intent(this, SelectedItemsControl.class);
      startActivity(intent);
}

My SelectedItemsControl.class code: 我的SelectedItemsControl.class代码:

public class SelectedItemsControl extends AppCompatActivity {

    ListView lv2 ;
    ArrayList<String> CheckoutList ;
    ArrayAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.selecteditems);

lv2 =  (ListView) findViewById(R.id.listviewtwo);
        CheckoutList = new ArrayList<>();
        adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_2,CheckoutList);
lv2.setAdapter(adapter);

    }
}

Your code Should look like 您的代码应如下所示

public void checkout(View view){
    Intent intent = new Intent(FirstActivity.this, SecondActivity.class); // no space in class name
    startActivity(intent); }//no space between Start and Activity.

check manifest. 检查清单。 Your activity is declared or not there 您的活动已声明或不存在

<activity android:name=".SelectedItemsControl" />

hope it helps you. 希望对您有帮助。 If you have some different problem please ask me will help you, If this doesn't help try second option 如果您有其他问题,请问我将为您提供帮助,如果这样做无济于事,请尝试第二种选择

public void checkout(View view){
    Intent intent = new Intent(FirstActivity.this, SecondActivity.class); 
    startActivity(intent); }

try to comment code in your second Activity. 尝试在第二个活动中注释代码。 It helps if you have any error in second activity. 如果您在第二项活动中有任何错误,它会有所帮助。

public class SelectedItemsControl extends AppCompatActivity {

    ListView lv2 ;
    ArrayList<String> CheckoutList ;
    ArrayAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.selecteditems);

/*lv2 =  (ListView) findViewById(R.id.listviewtwo);
        CheckoutList = new ArrayList<>();
        adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_2,CheckoutList);
lv2.setAdapter(adapter);*/

    }
}

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

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