-1

Firstly, i apologize but i am a beginner to android development and with the forum. When i go to run the application on my emulator i get the error; "the application (app name) has stopped unexpectedly. Please try again." And i am struggling to interpret my log cat. I have also tried adjusting 'MAIN' and 'MENU' names in the manifest and the src file to match up but know results unless i am missing something. Here is my logcat:

01-06 16:50:32.273: D/dalvikvm(490): GC_EXTERNAL_ALLOC freed 652 objects / 51480 bytes in 92ms
01-06 16:50:37.813: D/AndroidRuntime(490): Shutting down VM
01-06 16:50:37.813: W/dalvikvm(490): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-06 16:50:37.863: E/AndroidRuntime(490): FATAL EXCEPTION: main
01-06 16:50:37.863: E/AndroidRuntime(490): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.knight.baseproject/com.knight.baseproject.com.knight.baseproject.MENU}: java.lang.ClassNotFoundException: com.knight.baseproject.com.knight.baseproject.MENU in loader dalvik.system.PathClassLoader[/data/app/com.knight.baseproject-2.apk]
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.os.Looper.loop(Looper.java:123)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-06 16:50:37.863: E/AndroidRuntime(490):  at java.lang.reflect.Method.invokeNative(Native Method)
01-06 16:50:37.863: E/AndroidRuntime(490):  at java.lang.reflect.Method.invoke(Method.java:521)
01-06 16:50:37.863: E/AndroidRuntime(490):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-06 16:50:37.863: E/AndroidRuntime(490):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-06 16:50:37.863: E/AndroidRuntime(490):  at dalvik.system.NativeStart.main(Native Method)
01-06 16:50:37.863: E/AndroidRuntime(490): Caused by: java.lang.ClassNotFoundException: com.knight.baseproject.com.knight.baseproject.MENU in loader dalvik.system.PathClassLoader[/data/app/com.knight.baseproject-2.apk]
01-06 16:50:37.863: E/AndroidRuntime(490):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
01-06 16:50:37.863: E/AndroidRuntime(490):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
01-06 16:50:37.863: E/AndroidRuntime(490):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
01-06 16:50:37.863: E/AndroidRuntime(490):  ... 11 more

Here is the Manifest:

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

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

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

</manifest>

Here is the 'MAIN' java script:

package com.knight.baseproject;

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

public class MAIN extends Activity {

    @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.knight.baseproject.MENU");
                    startActivity(menuIntent);

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

                finally{
                    finish();
                }
            }
        };
        logoTimer.start();
    }


    @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;
    }

}

The 'MENU' java (which i believe to have no impact):

package com.knight.baseproject;

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.main);

    }

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



}
Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97
user3165683
  • 347
  • 1
  • 9
  • 28
  • http://stackoverflow.com/questions/4688277/java-lang-runtimeexception-unable-to-instantiate-activity-componentinfo – Niko Jan 06 '14 at 17:13
  • You can improve your questions by making them SSCCEs: http://sscce.org. – james.garriss Jan 07 '14 at 13:55
  • You can improve them even more by searching SO for questions that have already answered your question and then not posting your duplicate. – james.garriss Jan 07 '14 at 13:56
  • Voting SO members: this may not be a duplicate since the JVM is complaining about a different component. For those voting to close, perhaps you could explain why it applies even though the components are different. Perhaps this might apply in this case: [Could we please be a bit nicer to new users?](https://meta.stackexchange.com/questions/9953/could-we-please-be-a-bit-nicer-to-new-users) – jww Jan 15 '14 at 07:05

5 Answers5

1

Change

android:name=".com.knight.baseproject.MENU"

to

android:name="com.knight.baseproject.MENU"

in your manifest.

general_bearbrand
  • 827
  • 5
  • 13
  • 29
1
<activity
        android:name=".com.knight.baseproject.MENU"

This name starts with a . so it is interpreted as relative to the package name com.knight.baseproject, giving you com.knight.baseproject.com.knight.baseproject.MENU as seen in the exception stacktrace:

java.lang.ClassNotFoundException: com.knight.baseproject.com.knight.baseproject.MENU in loader dalvik.system.PathClassLoader[/data/app/com.knight.baseproject-2.apk]

Either remove the initial . or change the name to just .MENU.

laalto
  • 150,114
  • 66
  • 286
  • 303
0

You need to add your activity in your AndroidManifest.xml file.

Mike B
  • 5,390
  • 2
  • 23
  • 45
0

Try the following options.

Option 1

  1. Right-click on your project
  2. Click Android tools
  3. Click Fix project properties

Option 2

Click Project --> Properties --> Java Build Path --> Order and Export, you should tick the entries you use.

Option 3

Remove all of your libraries except Android.x.x and then cleaning your project by Project --> Clean and then adding your libraries back (don't forget to Check in order and export).

And one more place you need to check is Properties --> Java Compiler --> JDK Compliance.

Prem
  • 4,823
  • 4
  • 31
  • 63
  • Which order and export should i check, are they the ones that appear when i open the project in package explorer? – user3165683 Jan 06 '14 at 20:21
  • No. Right click the project name in Package explorer and click Properties. On the left side, select Java Build path. Now the fourth tab is "Order and Export" – Prem Jan 06 '14 at 20:25
  • Try option 1 and 3 first. If it doesn't work, check all your project related directories. Example - Test/src and Test/gen. and Android x.x.x and click Ok. – Prem Jan 06 '14 at 20:32
  • OK. (projectname)/src and (projectname)/gen have filled boxes and are not check/uncheckable. But below them is: android 4.4.2, android private libaries, android dependencies. So i should check 4.4.2 and dependencies? is this just good general practice and something i should always do? – user3165683 Jan 06 '14 at 20:43
0

Try to learn How to debug errors, you can read the stacktrace and also run the application through debugger. Read from top to bottom, you will find what actually happened.

01-06 16:50:37.863: E/AndroidRuntime(490): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.knight.baseproject/com.knight.baseproject.com.knight.baseproject.MENU}: java.lang.ClassNotFoundException: com.knight.baseproject.com.knight.baseproject.MENU in loader dalvik.system.PathClassLoader[/data/app/com.knight.baseproject-2.apk]

01-06 16:50:37.863: E/AndroidRuntime(490): Caused by: java.lang.ClassNotFoundException: com.knight.baseproject.com.knight.baseproject.MENU in loader dalvik.system.PathClassLoader[/data/app/com.knight.baseproject-2.apk]

if you read it properly, you would find that an exception occured "ClassNotFoundException" because it couldn't find the class.

I think it's because you didn't add your Activity in your AndroidManifest.xml, whatever activity you use in application should be defined in the manifest file.

It would be great if you could post your code & manifest.

Yauraw Gadav
  • 1,706
  • 1
  • 18
  • 39