我是Android新手,当我点击导航按钮时,我的应用程序失败或停止工作,导航按钮应该指向另一个活动。这是我导航到下一个活动的代码。
public void checkout(View view) {
Intent intent = new Intent(this, SelectedItemsControl.class);
startActivity(intent);
}
My 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);
}
}
答案 0 :(得分:1)
您的代码应该是
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.
答案 1 :(得分:0)
检查清单。您的活动是否已宣布
<activity android:name=".SelectedItemsControl" />
希望它对你有所帮助。如果你有一些不同的问题,请问我会帮助你,如果这没有帮助尝试第二个选项
public void checkout(View view){
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(intent); }
尝试在第二个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);*/
}
}