0

I created a new Android application project in Eclipse on Mac. I set it up Android 4.4.2 sdk.

When I installed this sample project in the physical Nexus 7 Tablet, it throws the following launching error . I have not added anything yet in this project, it is just a sample project created as it is.

Unfortunately has stopped

04-13 00:16:05.395: W/dalvikvm(6761): Unable to resolve superclass of Lcom/example/myfinaltest/MainActivity; (2)
04-13 00:16:05.395: W/dalvikvm(6761): Link of class 'Lcom/example/myfinaltest/MainActivity;' failed
04-13 00:16:05.395: D/AndroidRuntime(6761): Shutting down VM
04-13 00:16:05.395: W/dalvikvm(6761): threadid=1: thread exiting with uncaught exception (group=0x415bcba8)
04-13 00:16:05.395: E/AndroidRuntime(6761): FATAL EXCEPTION: main
04-13 00:16:05.395: E/AndroidRuntime(6761): Process: com.example.myfinaltest, PID: 6761
04-13 00:16:05.395: E/AndroidRuntime(6761): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myfinaltest/com.example.myfinaltest.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.myfinaltest.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myfinaltest-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.myfinaltest-2, /vendor/lib, /system/lib]]
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.os.Looper.loop(Looper.java:136)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.app.ActivityThread.main(ActivityThread.java:5017)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at java.lang.reflect.Method.invokeNative(Native Method)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at java.lang.reflect.Method.invoke(Method.java:515)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at dalvik.system.NativeStart.main(Native Method)
04-13 00:16:05.395: E/AndroidRuntime(6761): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myfinaltest.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myfinaltest-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.myfinaltest-2, /vendor/lib, /system/lib]]
04-13 00:16:05.395: E/AndroidRuntime(6761):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
04-13 00:16:05.395: E/AndroidRuntime(6761):     ... 11 more

Code:

package com.example.myfinaltest;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {

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

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

AndroidManifest.xml:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfinaltest"
    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"
        >
        <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>
    </application>

</manifest>

For, values/styles.xml and values-v11/styles.xml and values-v14/styles.xml

same values for all 3 xml's, however I commented App theme, because I was seeing errors building with Appcompat libs.

    <resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
    </style>
-->

    <!-- Application theme. 
    <style name="AppTheme" parent="AppBaseTheme">
    </style>
-->
</resources>
Stella
  • 1,728
  • 5
  • 41
  • 95

2 Answers2

1

Check your AndroidManifest.xml in order to see whether your activity is defined as follows.

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

The package name might not be "com.example.myfinaltest" in your case.

Osman Esen
  • 1,704
  • 2
  • 21
  • 46
0

Since you are using AppCompat and extending ActionBarActivity you need to specify the correct theme.

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfinaltest"
    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"> <!-- You need a theme -->
        <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>
    </application>

</manifest>

values/styles.xml:

You can delete all of them except values/styles.xml.

<resources>

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
    </style>

    <style name="AppTheme" parent="AppBaseTheme">
    </style>

</resources>
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
  • I am having building error with Appcompat: [2015-04-13 01:48:04 - MyFinalTest] Workspace/MyFinalTest/res/values/styles.xml:3: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. – Stella Apr 12 '15 at 20:17
  • I see you are using `Eclipse`, right-click your project and make sure `AppCompat` is added as a build resource. – Jared Burrows Apr 12 '15 at 20:18
  • Do I have set in here, Right click Properties->Java build path->Libraries? From where can i choose appcompat? – Stella Apr 12 '15 at 20:20
  • `AppCompat` is in your "Android SDK" folder on your machine. Why have you not made the switch to Android Studio? This is all done for you in Android Studio. – Jared Burrows Apr 12 '15 at 20:22
  • I am using Mac 10.10 Yosemite, Android studio doesn't supported. – Stella Apr 12 '15 at 20:22
  • Could you please give me the steps to add appcompat? – Stella Apr 12 '15 at 20:23
  • I am using Android Studio right now on Mac. Here is the download link for Mac: http://developer.android.com/sdk/index.html. – Jared Burrows Apr 12 '15 at 20:23
  • Stella, read my comments. I just told you how to add AppCompat. – Jared Burrows Apr 12 '15 at 20:24
  • Android studio supported only upto Mac 10.9 – Stella Apr 12 '15 at 20:26
  • Stella, why are you fighting with me? I am using Mac OSX 10.10.2 Yosimite. I am trying to help you. Here is the exact link if you want to download: https://dl.google.com/dl/android/studio/install/1.1.0/android-studio-ide-135.1740770-mac.dmg. – Jared Burrows Apr 12 '15 at 20:29
  • Oh ok, I'm not fighting, Sorry, Apologies..Thanks, I'll download it..Meanwhile I am trying to set it up in eclipse as well. I am trying to add appcompat like this, right click project Properties->Java build path->Libraries->Add external JARs. Is this correct? – Stella Apr 12 '15 at 20:32
  • Yes. You are very close: http://stackoverflow.com/questions/17903521/android-actionbar-how-to-add-supporting-library-v7-appcompat. – Jared Burrows Apr 12 '15 at 20:32
  • According to mentioned in that link you shared, I tried importing appcompat project into workspace first, it throws error in this appcompat project in res/values-v21/stylebase.xml file at this line, – Stella Apr 12 '15 at 20:45
  • Please Google for help. See the official docs here: https://developer.android.com/tools/support-library/setup.html#libs-without-res – Jared Burrows Apr 12 '15 at 20:47
  • I am installing Android studio as you suggested. I need to create one screen where I'll have to play an audio file from my server. This app should work on both Phone and Tab as well. If you have any sample playing audio from server, kindly share me the sample link and also sample link for having screen to work with phone and tab as well. – Stella Apr 12 '15 at 20:47
  • I have answered your original question. This is now becoming off-topic and turning into another question. – Jared Burrows Apr 12 '15 at 20:48
  • Sure..Just asked some help. – Stella Apr 12 '15 at 20:49
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/75071/discussion-between-jared-burrows-and-stella). – Jared Burrows Apr 12 '15 at 20:51