0
所以我有我的List類,它有一個浮動按鈕。我想做到這一點,當我點擊該按鈕時,它會進入我的另一個活動MainActivity。這是我的列表類的代碼。使用浮動按鈕開始活動
public class List extends Activity {
ImageButton floatButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
populateUsersList();
floatButton = (ImageButton) findViewById(R.id.imageButton);
floatButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent barcodes = new Intent (List.this, MainActivity.class);
startActivity(barcodes);
}
});
}
private void populateUsersList() {
// Construct the data source
ArrayList<User> arrayOfUsers = User.getUsers();
// Create the adapter to convert the array to views
UserAdapter adapter = new UserAdapter(this, arrayOfUsers);
// Attach the adapter to a ListView
ListView listView = (ListView) findViewById(R.id.lvUsers);
listView.setAdapter(adapter);
}
它似乎應該工作,但每次我點擊按鈕,這個錯誤代碼彈出。
06-15 11:34:46.299 2971-2971/com.example.pethoalpar.zxingexample E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pethoalpar.zxingexample, PID: 2971
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.pethoalpar.zxingexample/apn.keychains.MainActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1777)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
at android.app.Activity.startActivityForResult(Activity.java:3745)
at android.app.Activity.startActivityForResult(Activity.java:3706)
at android.app.Activity.startActivity(Activity.java:4016)
at android.app.Activity.startActivity(Activity.java:3984)
at apn.keychains.List$1.onClick(List.java:28)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
我該如何解決這個問題?
非常感謝,現在一切正常。 – user2543577
@ user2543577您可能想要回答以及接受答案。 – David