0

i am using Action Bar in my App, extends ActionBarActivity , but it is giving following error in Logcat,

02-12 21:59:53.252: E/AndroidRuntime(7062): FATAL EXCEPTION: main
02-12 21:59:53.252: E/AndroidRuntime(7062): Process: com.example.a_bar, PID: 7062
02-12 21:59:53.252: E/AndroidRuntime(7062): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.a_bar/com.example.a_bar.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.a_bar.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.a_bar-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.a_bar-1, /system/lib, /data/downloads]]
02-12 21:59:53.252: E/AndroidRuntime(7062):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
02-12 21:59:53.252: E/AndroidRuntime(7062):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-12 21:59:53.252: E/AndroidRuntime(7062):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-12 21:59:53.252: E/AndroidRuntime(7062):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-12 21:59:53.252: E/AndroidRuntime(7062):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-12 21:59:53.252: E/AndroidRuntime(7062):     at android.os.Looper.loop(Looper.java:136)
02-12 21:59:53.252: E/AndroidRuntime(7062):     at android.app.ActivityThread.main(ActivityThread.java:5021)
02-12 21:59:53.252: E/AndroidRuntime(7062):     at java.lang.reflect.Method.invokeNative(Native Method)
02-12 21:59:53.252: E/AndroidRuntime(7062):     at java.lang.reflect.Method.invoke(Method.java:515)
02-12 21:59:53.252: E/AndroidRuntime(7062):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
02-12 21:59:53.252: E/AndroidRuntime(7062):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
02-12 21:59:53.252: E/AndroidRuntime(7062):     at dalvik.system.NativeStart.main(Native Method)
02-12 21:59:53.252: E/AndroidRuntime(7062): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.a_bar.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.a_bar-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.a_bar-1, /system/lib, /data/downloads]]

Manifest is as below,

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.a_bar.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.AppCompat.Light" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

style.xml is as below,

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

</resources>

MainActivity is as below,

package com.example.a_bar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;

public class MainActivity extends ActionBarActivity {

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

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }
    }

i have added as library project android-support-v7-appcompat, in my App. And added theme into Manifest,

 android:theme="@style/Theme.AppCompat.Light" 

My App get crashed while stated . Why ClassNotFoundException generated ? But when i extend Activity instead of ActionBarActivity it is Running .

sandeep gupta
  • 301
  • 1
  • 3
  • 14
  • Post your code and AndroidManifest.xml. – Jared Burrows Feb 13 '15 at 06:12
  • I see your updated code, do you have the correct package name on your class? I am not seeing one at all. Is your IDE not showing your warnings? – Jared Burrows Feb 13 '15 at 06:18
  • Try this : http://stackoverflow.com/questions/19523167/android-classnotfoundexception-didnt-find-class-on-path – Yuva Raj Feb 13 '15 at 06:19
  • @Jared Burrows, yes i have used the correct package name – sandeep gupta Feb 13 '15 at 06:20
  • Your `AndroidManifest.xml`, `MainActivity.java` and `style.xml` are correct. Do you have anything in your `activity_main.xml` layout? Did you just create/import this project? – Jared Burrows Feb 13 '15 at 06:30
  • i just created new project in my IDE. activity_main.xml is nothing but the by default FrameLayout. When i extends Activity instead of ActionBarActivity, then it is running. – sandeep gupta Feb 13 '15 at 06:37
  • 1
    You should be using Android Studio. Since you are just starting, you should switch now. Have you tried cleaning your project, usually this is an issue in Eclipse? – Jared Burrows Feb 13 '15 at 06:59
  • @ Jared Borrows , i tried all , previously. – sandeep gupta Feb 13 '15 at 07:28
  • @ Jared Borrows, Thanks , Now it is working for ActionBarActivity also, i just update the sdk Android Support Libraries, and restart the Eclipse. thanks again. – sandeep gupta Feb 13 '15 at 10:05

2 Answers2

2

There is no need to import android.support.v7.app.ActionBarActivity because minSdkVersion of your project is 11, so the ActionBar will already be included in your app even if you don't extend ActionBarActivity. You need to import support library for ActionBar only when your application's minSdkVersion is less than 11.

Just import android.app.Activity and extend your class to Activity only.

Apurva
  • 7,871
  • 7
  • 40
  • 59
0

There are dependency issue. add support-v4 library and hope it will solve your issue.

Shankar
  • 518
  • 5
  • 16