Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7162641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:46:08+00:00 2026-05-28T13:46:08+00:00

Hi Ive written a simple android application with two xml pages, one has an

  • 0

Hi Ive written a simple android application with two xml pages, one has an image button which ive rigged to open the second xml page when it is clicked. The code returns no errors and runs fine but when I click the button in the android emulator it crashes and asks me to force close. Here is the code I am working on:

First Activity:

package com.android.Train;

import com.android.TrainMenu.MenuActivity;

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;

    public class TrainActivity extends Activity 
    {
        /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void goMenu(View v)
    {
      Intent myIntent = new Intent(this, MenuActivity.class);
      startActivity(myIntent);
    }    
}

First XML File:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageButton
        android:id="@+id/enterButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/button_enter"
        android:clickable="true"
        android:onClick="goMenu" />

    </LinearLayout>

Second Activity:

package com.android.TrainMenu;

import android.app.Activity;
import android.os.Bundle;

import com.android.Train.R;

public class MenuActivity extends Activity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);
    }
}

Second XML File:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

</RelativeLayout>

Any ideas on why this should crash?

Thanks in advance

I just ran it again, here is the logCat file

01-26 14:21:37.784: D/AndroidRuntime(287): Shutting down VM
01-26 14:21:37.784: W/dalvikvm(287): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-26 14:21:37.815: E/AndroidRuntime(287): FATAL EXCEPTION: main
01-26 14:21:37.815: E/AndroidRuntime(287): java.lang.IllegalStateException: Could not execute method of the activity
01-26 14:21:37.815: E/AndroidRuntime(287):  at android.view.View$1.onClick(View.java:2072)
01-26 14:21:37.815: E/AndroidRuntime(287):  at android.view.View.performClick(View.java:2408)
01-26 14:21:37.815: E/AndroidRuntime(287):  at android.view.View$PerformClick.run(View.java:8816)
01-26 14:21:37.815: E/AndroidRuntime(287):  at android.os.Handler.handleCallback(Handler.java:587)
01-26 14:21:37.815: E/AndroidRuntime(287):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-26 14:21:37.815: E/AndroidRuntime(287):  at android.os.Looper.loop(Looper.java:123)
01-26 14:21:37.815: E/AndroidRuntime(287):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-26 14:21:37.815: E/AndroidRuntime(287):  at java.lang.reflect.Method.invokeNative(Native Method)
01-26 14:21:37.815: E/AndroidRuntime(287):  at java.lang.reflect.Method.invoke(Method.java:521)
01-26 14:21:37.815: E/AndroidRuntime(287):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-26 14:21:37.815: E/AndroidRuntime(287):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-26 14:21:37.815: E/AndroidRuntime(287):  at dalvik.system.NativeStart.main(Native Method)
01-26 14:21:37.815: E/AndroidRuntime(287): Caused by: java.lang.reflect.InvocationTargetException
01-26 14:21:37.815: E/AndroidRuntime(287):  at com.android.Train.TrainActivity.goMenu(TrainActivity.java:23)
01-26 14:21:37.815: E/AndroidRuntime(287):  at java.lang.reflect.Method.invokeNative(Native Method)
01-26 14:21:37.815: E/AndroidRuntime(287):  at java.lang.reflect.Method.invoke(Method.java:521)
01-26 14:21:37.815: E/AndroidRuntime(287):  at android.view.View$1.onClick(View.java:2067)
01-26 14:21:37.815: E/AndroidRuntime(287):  ... 11 more
01-26 14:21:37.815: E/AndroidRuntime(287): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.Train/com.android.TrainMenu.MenuActivity}; have you declared this activity in your AndroidManifest.xml?
01-26 14:21:37.815: E/AndroidRuntime(287):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
01-26 14:21:37.815: E/AndroidRuntime(287):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
01-26 14:21:37.815: E/AndroidRuntime(287):  at android.app.Activity.startActivityForResult(Activity.java:2817)
01-26 14:21:37.815: E/AndroidRuntime(287):  at android.app.Activity.startActivity(Activity.java:2923)
01-26 14:21:37.815: E/AndroidRuntime(287):  ... 15 more

Android Manifest.XML

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.Train"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".TrainActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
        android:name=".MenuActivity"
        android:label="@string/app_name" />

    </application>

</manifest>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:46:08+00:00Added an answer on May 28, 2026 at 1:46 pm

    I think its because your MenuActivity class is in a different package to your TrainActivity class. I’m not sure how to do it with the package layout you have, but if you had the following:

    com.ardroid.train.TrainActivity
    com.ardroid.train.menu.MenuActivity
    

    Then your manifest entry would be:

    <activity 
        android:name=".menu.MenuActivity "
        android:label="@string/app_name" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written a simple control which basically displays a few words with an image
I've written a simple server application which will run distributed on several machines. My
I've written a application in Java which I am trying to port to Android
Ive written a Word addin in VS 2008 thats pretty simple, just adds a
I've written a simple Java applet to generate a technical image based upon some
I've written a simple PHP nusoap web service for an application and wish to
I've written a simple XML Document that I am trying to transform with an
I've written a simple top down parser using c#. It's a console application. I'd
I've written a simple MVC3 application and followed a tutorial on how to set
I've encountered a rather strange error. I've written an android application that uploads an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.