Reputation: 55
So I have my List class which has a floatingbutton. I want to make it so that when i click that button it goes into another one of my activities, MainActivity. This is the code I have for my list class.
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);
}
It seems like it should work, but every time i click the button, this error code pops up.
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)
How do I fix this?
Upvotes: 0
Views: 278
Reputation: 10205
You need to declare your activity at the manifest file.
Add this to your manifest:
<activity android:name=".MainActivity" android:screenOrientation="portrait" />
All your <activity... />
tags should be placed under the <application.. />
tag.
Upvotes: 2