我是Android的新手,当我单击"导航"按钮时,我的应用程序会失败或停止工作,这应该将我引向另一个活动。这是我导航到下一个活动的代码。
public void checkout(View view) {
Intent intent = new Intent(this, SelectedItemsControl.class);
startActivity(intent);
}
我的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);
}
}
您的代码应该看起来像
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.
检查清单。您的活动被声明或不在那里
<activity android:name=".SelectedItemsControl" />
希望它对您有帮助。如果您有不同的问题,请问我会为您提供帮助,如果这无助于尝试第二选项
public void checkout(View view){
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(intent); }
尝试在第二个活动中评论代码。如果您在第二个活动中有任何错误,它会有所帮助。
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);*/
}
}