Android: Multiple Classes to use same XML Layout



So I am having some trouble using multiple classes with just the one xml file. What I am trying to do is I have a difficultly selector the harder the difficultly the less time the user has in the game.


I have successfully set up my normal difficultly which loads from a button click with the xml file. To save making multiple xml files for easy and other difficulties I created a class with less time and linked it with setContentView(R.layout.activity_main);. Only one class at a time seems to be able to have it's contentview set to one xml file. Upon clicking the easy button the app crashes even though the same code works for the normal difficultly.


the code that calls each class is as follows:



private void setButtonOnClickListeners(){
normalBut.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent playgameN = new Intent(getApplicationContext(),MainActivity.class);
startActivity(playgameN);

}
});
easyBut.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent playgameE = new Intent(getApplicationContext(),EasyMain.class);
startActivity(playgameE);


}
});


This code works successfully but crashes on easy button press.


Both easy class and normal class have setContentView(R.layout.activity_main); in their respective on create.


The log I have when the button causes the crash is as follows:



01-07 20:29:48.630: I/Adreno200-EGLSUB(23442): <ConfigWindowMatch:2081>: Format RGBA_8888.
01-07 20:29:48.630: D/memalloc(23442): /dev/pmem: Mapped buffer base:0x51851000 size:4915200 offset:4300800 fd:67
01-07 20:29:48.780: D/memalloc(23442): /dev/pmem: Mapped buffer base:0x51f78000 size:1228800 offset:614400 fd:70
01-07 20:29:50.790: I/Adreno200-EGLSUB(23442): <ConfigWindowMatch:2081>: Format RGBA_8888.
01-07 20:29:50.800: D/memalloc(23442): /dev/pmem: Mapped buffer base:0x522a4000 size:1843200 offset:1228800 fd:73
01-07 20:29:50.820: D/memalloc(23442): /dev/pmem: Mapped buffer base:0x52466000 size:4300800 offset:3686400 fd:79
01-07 20:29:50.870: D/memalloc(23442): /dev/pmem: Unmapping buffer base:0x51851000 size:4915200 offset:4300800
01-07 20:29:50.870: D/memalloc(23442): /dev/pmem: Unmapping buffer base:0x51f78000 size:1228800 offset:614400
01-07 20:29:52.610: D/memalloc(23442): /dev/pmem: Mapped buffer base:0x51751000 size:1228800 offset:614400 fd:64
01-07 20:29:52.700: W/dalvikvm(23442): threadid=1: thread exiting with uncaught exception (group=0x40af09f0)
01-07 20:29:52.710: E/AndroidRuntime(23442): FATAL EXCEPTION: main
01-07 20:29:52.710: E/AndroidRuntime(23442): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.phil3992.colourguess/com.phil3992.colourguess.PractEnd}; have you declared this activity in your AndroidManifest.xml?
01-07 20:29:52.710: E/AndroidRuntime(23442): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
01-07 20:29:52.710: E/AndroidRuntime(23442): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
01-07 20:29:52.710: E/AndroidRuntime(23442): at android.app.Activity.startActivityForResult(Activity.java:3195)
01-07 20:29:52.710: E/AndroidRuntime(23442): at android.app.Activity.startActivity(Activity.java:3302)
01-07 20:29:52.710: E/AndroidRuntime(23442): at com.phil3992.colourguess.dif$2.onClick(dif.java:38)
01-07 20:29:52.710: E/AndroidRuntime(23442): at android.view.View.performClick(View.java:3528)
01-07 20:29:52.710: E/AndroidRuntime(23442): at android.view.View$PerformClick.run(View.java:14235)
01-07 20:29:52.710: E/AndroidRuntime(23442): at android.os.Handler.handleCallback(Handler.java:605)
01-07 20:29:52.710: E/AndroidRuntime(23442): at android.os.Handler.dispatchMessage(Handler.java:92)
01-07 20:29:52.710: E/AndroidRuntime(23442): at android.os.Looper.loop(Looper.java:137)
01-07 20:29:52.710: E/AndroidRuntime(23442): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-07 20:29:52.710: E/AndroidRuntime(23442): at java.lang.reflect.Method.invokeNative(Native Method)
01-07 20:29:52.710: E/AndroidRuntime(23442): at java.lang.reflect.Method.invoke(Method.java:511)
01-07 20:29:52.710: E/AndroidRuntime(23442): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
01-07 20:29:52.710: E/AndroidRuntime(23442): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
01-07 20:29:52.710: E/AndroidRuntime(23442): at dalvik.system.NativeStart.main(Native Method)


How can I get it so all my classes can individual run on the same layout when called? It's really confused me as the code work perfectly for one class but not the other thus leading me to believe the setContent is the cause of the issue


UPDATE:


Manifest:


class is declared like so:



<activity
android:name=".EasyMain"
android:label="@string/app_name"
android:screenOrientation="portrait">

</activity>

No comments:

Post a Comment