Итак, у меня есть класс 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