Green Man
Green Man

Reputation: 21

The application has stopped unexpectedly. Please try again. Android Error

I created two activities and i wanted to switch between them after 5 seconds. the first activity lunches as expected but after 5 seconds i get the error: The application has stopped unexpectedly.

my package is called com.example.thebasics and it contains two classes:

package com.example.thebasics;

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

public class menu extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
    }

}

and:

package com.example.thebasics;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        Thread logoTimer = new Thread(){
            public void run(){
                try{
                    sleep(5000);
                    Intent menuIntent = new Intent("com.example.thebasics.MENU");
                    startActivity(menuIntent);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                finally{
                    finish();
                }
            }
        }; // end of Thread
        logoTimer.start();
    }

this is my manifest file:

 <activity
        android:name=".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=".menu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.thebasics.MENU" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

i have two layout files activity_main.xml and splash.xml i should note that both activities works fine alone.. but the combination with the 5 seconds is not working.

LogCat:

02-14 19:16:10.853: E/AndroidRuntime(274): FATAL EXCEPTION: Thread-8
02-14 19:16:10.853: E/AndroidRuntime(274): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.thebasics.menu }
02-14 19:16:10.853: E/AndroidRuntime(274):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
02-14 19:16:10.853: E/AndroidRuntime(274):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
02-14 19:16:10.853: E/AndroidRuntime(274):  at android.app.Activity.startActivityForResult(Activity.java:2817)
02-14 19:16:10.853: E/AndroidRuntime(274):  at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
02-14 19:16:10.853: E/AndroidRuntime(274):  at android.app.Activity.startActivity(Activity.java:2923)
02-14 19:16:10.853: E/AndroidRuntime(274):  at com.example.thebasics.MainActivity$1.run(MainActivity.java:18)
02-14 19:16:11.554: I/ARMAssembler(58): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x35ea20:0x35eadc] in 402548 ns
02-14 19:16:13.194: I/Process(274): Sending signal. PID: 274 SIG: 9
02-14 19:16:13.214: I/ActivityManager(58): Process com.example.thebasics (pid 274) has died.
02-14 19:16:13.224: W/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44f76318
02-14 19:20:50.880: D/SntpClient(58): request time failed: java.net.SocketException: Address family not supported by protocol
: E/(): Device disconnected: 1
: E/(): Device disconnected

Upvotes: 0

Views: 478

Answers (2)

CyborgFish
CyborgFish

Reputation: 356

Fix misspellings (defualt in manifest)

And try with the builder Intent(Context packageContext, Class cls) for creating the intent instead. In your case:

Intent menuIntent = new Intent(this, menu.class);

Upvotes: 0

Psypher
Psypher

Reputation: 10829

The class name should be in lowercase as below:

Intent menuIntent = new Intent("com.example.thebasics.menu");

ALso in your Androidmanifest.xml, you had same issue and the DEFAULT was mispelled

<intent-filter>
        <action android:name="com.example.thebasics.menu" />

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>

Upvotes: 1

Related Questions