user2595136
user2595136

Reputation:

Eclipse "Sorry- The application (Appname) has stopped unexpectedly. Please try again"

Hey im a begginer in android coding and ive been following this series on youtube. Whenever I run my project as an android application and go to the emulator to select it, it gives me "Sorry- The application (Appname) has stopped unexpectedly. Please try again" Eclipse doesnt give me any error line to where the problem is and so it is very frustrating.. Ive been looking on the internet for answers to this, but I havent been able to fix it. I think it has something to do with my Manifest. Whenever i run my application there are errors on my LogCat.

My application is a small app that when selected will first open a logo screen for 3 seconds then it will take you to an interface where there are 2 buttons to choose from. Both buttons lead to this thing that edits text.

Ive posted all my code below and please guys keep in mind when you answer that I am a begginer and might not understand some terms. Thank you!

Here is my LogCat when i try to start it

07-20 20:19:17.382: D/dalvikvm(254): GC_EXTERNAL_ALLOC freed 663 objects / 51912 bytes in 177ms
07-20 20:19:19.791: D/AndroidRuntime(254): Shutting down VM
07-20 20:19:19.801: W/dalvikvm(254): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-20 20:19:19.811: E/AndroidRuntime(254): FATAL EXCEPTION: main
07-20 20:19:19.811: E/AndroidRuntime(254): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.thepasics/com.example.thepasics.Menu}: java.lang.ClassNotFoundException: com.example.thepasics.Menu in loader dalvik.system.PathClassLoader[/data/app/com.example.thepasics-2.apk]
07-20 20:19:19.811: E/AndroidRuntime(254):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
07-20 20:19:19.811: E/AndroidRuntime(254):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-20 20:19:19.811: E/AndroidRuntime(254):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-20 20:19:19.811: E/AndroidRuntime(254):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-20 20:19:19.811: E/AndroidRuntime(254):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-20 20:19:19.811: E/AndroidRuntime(254):  at android.os.Looper.loop(Looper.java:123)
07-20 20:19:19.811: E/AndroidRuntime(254):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-20 20:19:19.811: E/AndroidRuntime(254):  at java.lang.reflect.Method.invokeNative(Native Method)
07-20 20:19:19.811: E/AndroidRuntime(254):  at java.lang.reflect.Method.invoke(Method.java:521)
07-20 20:19:19.811: E/AndroidRuntime(254):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-20 20:19:19.811: E/AndroidRuntime(254):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-20 20:19:19.811: E/AndroidRuntime(254):  at dalvik.system.NativeStart.main(Native Method)
07-20 20:19:19.811: E/AndroidRuntime(254): Caused by: java.lang.ClassNotFoundException: com.example.thepasics.Menu in loader dalvik.system.PathClassLoader[/data/app/com.example.thepasics-2.apk]
07-20 20:19:19.811: E/AndroidRuntime(254):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-20 20:19:19.811: E/AndroidRuntime(254):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-20 20:19:19.811: E/AndroidRuntime(254):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-20 20:19:19.811: E/AndroidRuntime(254):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-20 20:19:19.811: E/AndroidRuntime(254):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
07-20 20:19:19.811: E/AndroidRuntime(254):  ... 11 more

My Manifest

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


    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.thepasics.Main"
            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.thePasics.MENU" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
         <activity
            android:name=".TutorialOne"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.example.thePasics.TUTORIALONE" />

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

</manifest>

I have 3 Java files which are Menu.java Main.java TutorialOne.java. This one is the Main one

package com.example.thepasics;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;


public class Main extends Activity {
    MediaPlayer logoMusic;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        logoMusic = MediaPlayer.create(Main.this, R.raw.music);
        logoMusic.start();

        Thread logoTimer = new Thread(){
            public void run(){
                try{
                    sleep(2000);
                    Intent menuIntent = new Intent("com.example.thePasics.MENU");
                    startActivity(menuIntent);

                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                finally{
                    finish();
                }
            }

        };
        logoTimer.start();

    }

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

}

This One is the menu.java

package com.example.thepasics;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class menu extends Activity{

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

        //Button sound
        final MediaPlayer buttonSound = MediaPlayer.create(menu.this, R.raw.buttonsound);

        //Setting up button references
        Button tut1 = (Button) findViewById(R.id.button1); 
        Button tut2 = (Button) findViewById(R.id.button2); 

        tut1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                buttonSound.start();
                startActivity(new Intent("com.example.thepasics.TUTORIALONE"));

            }
        });

        tut2.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                buttonSound.start();
                startActivity(new Intent("com.example.thepasics.TutorialOne"));

            }
        });
    }

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


}

The third one is the TutorialOne.java

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

public class TutorialOne extends Activity implements OnCheckedChangeListener{

    TextView textOut;
    EditText textIn;
    RadioGroup gravityG, styleG;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tutorial1);
        textOut = (TextView) findViewById(R.id.tvChange);
        textIn = (EditText) findViewById(R.id.editText1);
        gravityG = (RadioGroup) findViewById(R.id.rgGravity);
        gravityG.setOnCheckedChangeListener(this);
        styleG = (RadioGroup) findViewById(R.id.rgStyle);
        styleG.setOnCheckedChangeListener(this);
        Button gen = (Button) findViewById(R.id.bGenerate);

        gen.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                textOut.setText(textIn.getText());

            }
        });

    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        // TODO Auto-generated method stub
        switch(checkedId){
        case R.id.rbLeft: 
            textOut.setGravity(Gravity.LEFT);
            break;
        case R.id.rbCenter: 
            textOut.setGravity(Gravity.CENTER);
            break;
        case R.id.rbRight: 
            textOut.setGravity(Gravity.RIGHT);
            break;  

        case R .id.rbNormal:
            textOut.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL), Typeface.NORMAL);
            break;
        case R .id.rbItalic:
            textOut.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC), Typeface.ITALIC);
            break;
        case R .id.rbBold:
            textOut.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD), Typeface.BOLD);
            break;

        }



    }

}

My 3 xml files are splash, tutorial1 and main

this one is main.xml

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

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Choose a function" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button1"
        android:textSize="25dp"
        android:textStyle="bold" 
        android:id="@+id/button1"/>

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button2"
        android:textSize="25dp"
        android:textStyle="bold" 
        android:id="@+id/button2"/>
</LinearLayout>

second one is splash.xml

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


</LinearLayout>

third one is tutorial1.xml

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

    <EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="2" >

        <TextView
            android:id="@+id/tvStyle"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Style"
            android:textSize="25dp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/tvGravity"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Gravity"
            android:textSize="25dp"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="2" >

        <RadioGroup
            android:id="@+id/rgStyle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >

            <RadioButton
                android:id="@+id/rbNormal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Normal" />

            <RadioButton
                android:id="@+id/rbItalic"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Italic" />

            <RadioButton
                android:id="@+id/rbBold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Bold" />
        </RadioGroup>

        <RadioGroup
            android:id="@+id/rgGravity"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >

            <RadioButton
                android:id="@+id/rbLeft"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Left" />

            <RadioButton
                android:id="@+id/rbCenter"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Center" />

            <RadioButton
                android:id="@+id/rbRight"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Right" />
        </RadioGroup>
    </LinearLayout>

    <TextView
        android:id="@+id/tvChange"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Type in Text and Press the Button Below" />

    <Button
        android:id="@+id/bGenerate"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Generate" />

</LinearLayout>

Upvotes: 0

Views: 9473

Answers (4)

user2517419
user2517419

Reputation:

I only have looked into your Logcat:

07-20 20:19:19.801: W/dalvikvm(254): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-20 20:19:19.811: E/AndroidRuntime(254): FATAL EXCEPTION: main
07-20 20:19:19.811: E/AndroidRuntime(254): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.thepasics/com.example.thepasics.Menu}: java.lang.ClassNotFoundException: com.example.thepasics.Menu in loader dalvik.system.PathClassLoader[/data/app/com.example.thepasics-2.apk]

Your app is crashing becuase your com.example.thepasics.Menu is not being found, and also use android:name=".Menu" instead of android:name="Menu".

Upvotes: 0

ianhanniballake
ianhanniballake

Reputation: 200020

Your Manifest and menu activity don't match. Your manifest has

<activity
    android:name="Menu" ...

which first of all isn't a valid name. It could be either android:name=".Menu" to refer to com.com.example.thepasics.Menu or you could use the fully qualified name (as you did for com.example.thepasics.Main).

In addition, your class is named menu, not Menu - remember it is case sensitive. Java convention has class names starting with a capital letter, so it should probably be corrected to Menu.

Upvotes: 1

Vipul
Vipul

Reputation: 28093

You have specified wrong class name in manifest.xml

Replace

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

with

  <activity
                android:name="com.example.thepasics.menu"
                android:label="@string/app_name" >

Upvotes: 1

Gatekeeper
Gatekeeper

Reputation: 7138

Your Menu class is actually called "menu" and not "MENU".

public class menu extends Activity{

Try changing "com.example.thePasics.MENU" to "com.example.thePasics.menu" throughout your app.

Upvotes: 0

Related Questions