user3572985
user3572985

Reputation: 3

From splash to the actual App. unfortunately APP has stopped

I having issues on my first android app. I cant figure out why, after 5 seconds wait, the app exits and says "unfortunately APP has stopped". The app its pretty basic. just add and sub 1 number. but it shows an image when started.

MainActivity.java

package com.example.helloworld;

 import android.os.Bundle;
 import android.app.Activity;
 import android.view.Menu;
 import android.view.View;
 import android.widget.Button;
 import android.widget.TextView;

 public class MainActivity extends Activity {

        int counter;
        Button add, sub;
         TextView display;


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

    counter=0;
    add = (Button) findViewById(R.id.bAdd);
    sub = (Button) findViewById(R.id.bSub);
    display = (TextView) findViewById(R.id.tvDisplay);

    add.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            counter++;
            display.setText("Your total is " + counter);
        }
    });
    sub.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            counter--;
            display.setText("Your total is " + counter);
        }
    });
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

 }

HelloWorldManifest.java

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Splash"
        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=".startingPoint"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.helloworld.STARTINGPOINT"/> 
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>


</application>

And the Splash.java package com.example.helloworld;

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

 public class Splash extends Activity {

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

    Thread timer = new Thread(){
        public void run() {
            try {
                Thread.sleep(5000);

            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally{

                Intent openStartingPoint = new Intent("com.example.helloworld.STARTINGPOINT");
                startActivity(openStartingPoint);
            }
        }

    };
    timer.start();
}

  }

LOGCAT

 04-25 08:25:33.391: D/AndroidRuntime(1016): Shutting down VM
 04-25 08:25:33.391: W/dalvikvm(1016): threadid=1: thread exiting with uncaught exception (group=0x41465700)
 04-25 08:25:33.471: E/AndroidRuntime(1016): FATAL EXCEPTION: main
 04-25 08:25:33.471: E/AndroidRuntime(1016): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.helloworld/com.example.helloworld.startingPoint}: java.lang.ClassNotFoundException: Didn't find class "com.example.helloworld.startingPoint" on path: DexPathList[[zip file "/data/app/com.example.helloworld-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.helloworld-1, /system/lib]]
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at android.os.Handler.dispatchMessage(Handler.java:99)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at android.os.Looper.loop(Looper.java:137)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at android.app.ActivityThread.main(ActivityThread.java:5103)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at java.lang.reflect.Method.invokeNative(Native Method)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at java.lang.reflect.Method.invoke(Method.java:525)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at dalvik.system.NativeStart.main(Native Method)
 04-25 08:25:33.471: E/AndroidRuntime(1016): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.helloworld.startingPoint" on path: DexPathList[[zip file "/data/app/com.example.helloworld-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.helloworld-1, /system/lib]]
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
 04-25 08:25:33.471: E/AndroidRuntime(1016):    ... 11 more
 04-25 08:35:02.411: D/dalvikvm(1066): GC_FOR_ALLOC freed 52K, 7% free 2631K/2800K, paused 42ms, total 44ms

The problem is from splash to the actual app. separeted they both work well. Thanks

EDIT: At the manifest changed

action android:name=".STARTINGPOINT"

to

action android:name="com.example.helloworld.STARTINGPOINT" 

Because that's how it was. i changed to try make thinks work. sorry

Upvotes: 0

Views: 171

Answers (2)

Stealth Rabbi
Stealth Rabbi

Reputation: 10346

You are trying to start an activity of the name STARTINGPOINT, but you don't have a class of that name.

Your Android manifest activity android:name property should be the same package/class name of the activity java file. Change it to

android:name="com.example.helloworld.MainActivity"

Also, you can use your intent without using a string literal:

Intent intent = new Intent(this, MainActivity.class);

Upvotes: 1

Pararth
Pararth

Reputation: 8134

From the code you have posted, looks like there is no "STARTINGPOINT", there's only Splash and MainActivity, which needs to be declared in the manifest.

Need to add this to your manifest:

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

And, in Splash, you need to start the MainActivity via intent,

Intent openStartingPoint = new Intent(Splash.this, MainActivity.class);  

Rest of it looks fine, do you have any activity named STARTINGPOINT? or just remove this from manifest:

 <activity
        android:name=".startingPoint"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name=".STARTINGPOINT" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>  

The compiler cannot identify a class "STARTINGPOINT", that is your exception.

Upvotes: 1

Related Questions