tags:

views:

50

answers:

1

I'm relatively new to programming in general so be gentle =| I'm trying to start a new activity from a basic one that displays a couple of text inputs, a checkbox, and a button. When the button is pressed I want it to switch to the new activity. The code compiles but when I press the button in Android it simply crashes. Any help would be greatly appreciated.

Here is the code sample:

public class Something extends Activity implements OnClickListener
{

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);

    Button login = (Button)findViewById(R.id.login);
    login.setOnClickListener(this);

}

@Override
public void onClick(View v) 
{

    startActivity(new Intent().setClass(Something.this, That.class));
}
}

Edit: Adding what I hope is the stack trace =/ Editx2: Heres the adb logcat, hope it makes sense to someone lol

I/ActivityManager( 240): Starting activity: Intent { cmp=jano.huerta.sfgc/.HOME } D/AndroidRuntime(13612): Shutting down VM W/dalvikvm(13612): threadid=1: thread exiting with uncaught exception (group=0x4 0025a08) E/AndroidRuntime(13612): FATAL EXCEPTION: main E/AndroidRuntime(13612): java.lang.RuntimeException: Unable to start activity Co mponentInfo{jano.huerta.sfgc/jano.huerta.sfgc.HOME}: android.content.ActivityNot FoundException: Unable to find explicit activity class {jano.huerta.sfgc/jano.hu erta.sfgc.SUMMARY}; have you declared this activity in your AndroidManifest.xml?

E/AndroidRuntime(13612): at android.app.ActivityThread.performLaunchActiv ity(ActivityThread.java:2787) E/AndroidRuntime(13612): at android.app.ActivityThread.handleLaunchActivi ty(ActivityThread.java:2803) E/AndroidRuntime(13612): at android.app.ActivityThread.access$2300(Activi tyThread.java:135) E/AndroidRuntime(13612): at android.app.ActivityThread$H.handleMessage(Ac tivityThread.java:2136) E/AndroidRuntime(13612): at android.os.Handler.dispatchMessage(Handler.ja va:99) E/AndroidRuntime(13612): at android.os.Looper.loop(Looper.java:144) E/AndroidRuntime(13612): at android.app.ActivityThread.main(ActivityThrea d.java:4937) E/AndroidRuntime(13612): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(13612): at java.lang.reflect.Method.invoke(Method.java:5 21) E/AndroidRuntime(13612): at com.android.internal.os.ZygoteInit$MethodAndA rgsCaller.run(ZygoteInit.java:868) E/AndroidRuntime(13612): at com.android.internal.os.ZygoteInit.main(Zygot eInit.java:626) E/AndroidRuntime(13612): at dalvik.system.NativeStart.main(Native Method)

E/AndroidRuntime(13612): Caused by: android.content.ActivityNotFoundException: U nable to find explicit activity class {jano.huerta.sfgc/jano.huerta.sfgc.SUMMARY }; have you declared this activity in your AndroidManifest.xml? E/AndroidRuntime(13612): at android.app.Instrumentation.checkStartActivit yResult(Instrumentation.java:1563) E/AndroidRuntime(13612): at android.app.ActivityThread.resolveActivityInf o(ActivityThread.java:2597) E/AndroidRuntime(13612): at android.app.LocalActivityManager.startActivit y(LocalActivityManager.java:277) E/AndroidRuntime(13612): at android.widget.TabHost$IntentContentStrategy. getContentView(TabHost.java:651) E/AndroidRuntime(13612): at android.widget.TabHost.setCurrentTab(TabHost. java:323) E/AndroidRuntime(13612): at android.widget.TabHost.addTab(TabHost.java:21 3) E/AndroidRuntime(13612): at jano.huerta.sfgc.HOME.onCreate(HOME.java:23) E/AndroidRuntime(13612): at android.app.Instrumentation.callActivityOnCre ate(Instrumentation.java:1069) E/AndroidRuntime(13612): at android.app.ActivityThread.performLaunchActiv ity(ActivityThread.java:2751) E/AndroidRuntime(13612): ... 11 more W/ActivityManager( 240): Force finishing activity jano.huerta.sfgc/.HOME W/ActivityManager( 240): Force finishing activity jano.huerta.sfgc/.SFGC W/ActivityManager( 240): Activity pause timeout for HistoryRecord{466bbec0 jano .huerta.sfgc/.HOME} D/dalvikvm( 406): GC_EXPLICIT freed 418 objects / 26008 bytes in 90ms I/Process (13612): Sending signal. PID: 13612 SIG: 9 I/ActivityManager( 240): Process jano.huerta.sfgc (pid 13612) has died. I/WindowManager( 240): WIN DEATH: Window{466cb800 jano.huerta.sfgc/jano.huerta. sfgc.SFGC paused=true} W/ActivityManager( 240): Activity destroy timeout for HistoryRecord{46654450 ja no.huerta.sfgc/.SFGC}

A: 

The most common mistake here is forgetting to register the 'That' activity in your AndroidManifest.xml. Have you done that?

Also, it would be much easier to help you if you pasted the stack trace from your crash. You can see crash info, amongst other logging, by running adb logcat.

blucz
I have registered the "THAT" activity with the same intent-filter as "Something" but still crashes. Unsure how to get a stack trace. I have the debugger running in Eclipse but I'm still figuring out how to make any sense of it.Edit: I think I figure out the stack trace, will edit question.
Alejandro Huerta
That stacktrace looks incomplete as I don't see anything that looks like your code in there. Normally in the log, you see a stacktrace like that one followed by a smaller stacktrace that is mostly limited to your code. This only tells half of the story. Not sure if this is eclipse's fault or yours, but adb logcat really is the simplest way.
blucz
Ok, I wasn't sure if it was possible to send the logcat command within Eclipse so I opened a cmd shell and took the log from there. I hope it came out properly and I can see that it does have code related to mine. I appreciate the help.
Alejandro Huerta
@Alejandro, Which is the SUMMARY Activity? Did u change it here for our benefit?
st0le
Well... I figured out what the problem was. I was exactly what you mentioned earlier with the Manifest. I forgot to add the Summary activity for the tabHost. Ah I feel... slow lol. Thank you very much, the logcat helped me figure it out and now I know better. Thanks again.@st0le no thats an actual activity with a tabHost I am using, but apparently I forgot to add that one. The problem has been fixed =D
Alejandro Huerta