I am not able to switch to the listactivity from my main acitivity , i created the listactivity by watching an video tutorial and followed the same steps but as soon as i click on the button to switch to the menu i am getting error “Unfortunately the program has stopped working “
Button button1;
button1 = (Button)findViewById(R.id.but1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(MainActivity.this,Menu.class);
startActivity(i);
The Menu class is as follows :
public class Menu extends ListActivity{
String classes[] = {"First","Second","Third"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this,android.R.layout.simple_list_item_1, classes));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese=classes[position];
try{
Class ourClass=Class.forName("com.ashsoft.basiccprogram." + cheese);
Intent ourIntent=new Intent(Menu.this,ourClass);
startActivity(ourIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
Logcat :
Log file : `01-13 13:53:03.481: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:03.481: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:03.481: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:04.511: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:04.521: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:05.602: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:05.602: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:05.681: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:05.771: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.001: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.071: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.071: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.181: I/Choreographer(1400): Skipped 68 frames! The application may be doing too much work on its main thread.
01-13 13:53:06.362: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.442: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.491: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.501: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.511: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.532: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.581: D/gralloc_goldfish(1400): Emulator without GPU emulation detected.
01-13 13:53:06.702: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.851: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.741: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.782: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.801: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.801: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.872: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.911: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.931: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.951: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:17.052: D/AndroidRuntime(1400): Shutting down VM
01-13 13:53:17.052: W/dalvikvm(1400): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
01-13 13:53:17.151: E/AndroidRuntime(1400): FATAL EXCEPTION: main
01-13 13:53:17.151: E/AndroidRuntime(1400): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.ashsoft.basiccprogram/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?
01-13 13:53:17.151: E/AndroidRuntime(1400): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
01-13 13:53:17.151: E/AndroidRuntime(1400): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
01-13 13:53:17.151: E/AndroidRuntime(1400): at android.app.Activity.startActivityForResult(Activity.java:3370)
01-13 13:53:17.151: E/AndroidRuntime(1400): at android.app.Activity.startActivityForResult(Activity.java:3331)
01-13 13:53:17.151: E/AndroidRuntime(1400): at android.app.Activity.startActivity(Activity.java:3566)
01-13 13:53:17.151: E/AndroidRuntime(1400): at android.app.Activity.startActivity(Activity.java:3534)
01-13 13:53:17.151: E/AndroidRuntime(1400): at com.ashsoft.basiccprogram.MainActivity$1.onClick(MainActivity.java:27)
01-13 13:53:17.151: E/AndroidRuntime(1400): at android.view.View.performClick(View.java:4202)
01-13 13:53:17.151: E/AndroidRuntime(1400): at android.view.View$PerformClick.run(View.java:17340)
01-13 13:53:17.151: E/AndroidRuntime(1400): at android.os.Handler.handleCallback(Handler.java:725)
01-13 13:53:17.151: E/AndroidRuntime(1400): at android.os.Handler.dispatchMessage(Handler.java:92)
01-13 13:53:17.151: E/AndroidRuntime(1400): at android.os.Looper.loop(Looper.java:137)
01-13 13:53:17.151: E/AndroidRuntime(1400): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-13 13:53:17.151: E/AndroidRuntime(1400): at java.lang.reflect.Method.invokeNative(Native Method)
01-13 13:53:17.151: E/AndroidRuntime(1400): at java.lang.reflect.Method.invoke(Method.java:511)
01-13 13:53:17.151: E/AndroidRuntime(1400): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-13 13:53:17.151: E/AndroidRuntime(1400): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-13 13:53:17.151: E/AndroidRuntime(1400): at dalvik.system.NativeStart.main(Native Method)
01-13 13:53:25.911: I/Process(1400): Sending signal. PID: 1400 SIG: 9
`
Manifest code :
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.ashsoft.basiccprogram.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ashsoft.basiccprogram.First"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.FIRST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ashsoft.basiccprogram.Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
The tutorial which i used did not use any xml file for the list.
Main problem is that the list is not showing up . Whenever i click on the button for menu from the main activity it stops working.
It seems you haven’t registered that Menu class in your manifest file.
If it still doesn’t work, post the logcat, so that there would be chances of having my answer edited.
EDIT:
First thing is your long process task must be sorrounded with asynctask.
For the time being let us leave that. Just try this:
Your ListScreenActivity: