ActionBarActivity will catch an error on the phone

** I was recommended for using ActionBar Activity ** Here is the previous code

import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } 

I wrote a new application and followed the tips.

 import android.os.Bundle; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; public class MainActivity extends ActionBarActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActionBar actionBar =getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } } 

if I use ACtionBarActivity instead of Activity
I will catch an error message on the phone when I try to start it. Please tell me what I am doing wrong.

information from logcat

  07-27 15:14:19.942: I/Process(21715): Sending signal. PID: 21715 SIG: 9 07-27 15:34:38.521: W/dalvikvm(23579): Unable to resolve superclass of Lcom/example/project/MainActivity; (532) 07-27 15:34:38.521: W/dalvikvm(23579): Link of class 'Lcom/example/project/MainActivity;' failed 07-27 15:34:38.521: D/AndroidRuntime(23579): Shutting down VM 07-27 15:34:38.521: W/dalvikvm(23579): threadid=1: thread exiting with uncaught exception (group=0x40ae5210) 07-27 15:34:38.521: E/AndroidRuntime(23579): FATAL EXCEPTION: main 07-27 15:34:38.521: E/AndroidRuntime(23579): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.project/com.example.project.MainActivity}: java.lang.ClassNotFoundException: com.example.project.MainActivity 07-27 15:34:38.521: E/AndroidRuntime(23579): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891) 07-27 15:34:38.521: E/AndroidRuntime(23579): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992) 07-27 15:34:38.521: E/AndroidRuntime(23579): at android.app.ActivityThread.access$600(ActivityThread.java:127) 07-27 15:34:38.521: E/AndroidRuntime(23579): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158) 07-27 15:34:38.521: E/AndroidRuntime(23579): at android.os.Handler.dispatchMessage(Handler.java:99) 07-27 15:34:38.521: E/AndroidRuntime(23579): at android.os.Looper.loop(Looper.java:137) 07-27 15:34:38.521: E/AndroidRuntime(23579): at android.app.ActivityThread.main(ActivityThread.java:4441) 07-27 15:34:38.521: E/AndroidRuntime(23579): at java.lang.reflect.Method.invokeNative(Native Method) 07-27 15:34:38.521: E/AndroidRuntime(23579): at java.lang.reflect.Method.invoke(Method.java:511) 07-27 15:34:38.521: E/AndroidRuntime(23579): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823) 07-27 15:34:38.521: E/AndroidRuntime(23579): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590) 07-27 15:34:38.521: E/AndroidRuntime(23579): at dalvik.system.NativeStart.main(Native Method) 07-27 15:34:38.521: E/AndroidRuntime(23579): Caused by: java.lang.ClassNotFoundException: com.example.project.MainActivity 07-27 15:34:38.521: E/AndroidRuntime(23579): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 07-27 15:34:38.521: E/AndroidRuntime(23579): at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 07-27 15:34:38.521: E/AndroidRuntime(23579): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 07-27 15:34:38.521: E/AndroidRuntime(23579): at android.app.Instrumentation.newActivity(Instrumentation.java:1023) 07-27 15:34:38.521: E/AndroidRuntime(23579): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882) 07-27 15:34:38.521: E/AndroidRuntime(23579): ... 11 more 07-27 15:34:38.531: I/Process(23579): Sending signal. PID: 23579 SIG: 9 

edit and export screenshot http://i.stack.imgur.com/MNfc1.jpg

screenshot 1-7

http://i.stack.imgur.com/NTpP3.jpg

+4
android android-actionbar android-support-library android-actionbar-compat
source share
3 answers

I did it all by moving “Android Personal Libraries” and “Android Dependencies” to the top of the list in the “Order and Export” section in my application project. Also I do not have android-support-v7-appcompat support in this list. And in the android-support-v7-appcompat project, I do not have support banners in the Order and Export list, but "Private Android Libraries" is checked. Please also check the links below:

Configuring ActionBarCompat Support Library in Eclipse

Implementing an action bar using the ActionBarCompat support library on Android

+5
source share

Ensure that the support library is added to the project and exported. You can do this in Eclipse by looking at the properties of your project, by clicking the Java Build Path , then the Order and Export tab. Then make sure Android Private Libraries checked.

You have completed the following steps: http://developer.android.com/tools/support-library/setup.html#

+1
source share

If you were with Android Studio, then exactly the same stack trace. I think this is because Android cannot find a suitable theme for ActionBarActivity.

Anyway, so I decided this:

Add the following to your MainActivity in AndroidManifest.xml:

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

If it works now - great! If Android Studio cannot find the theme: Copy the files

 sdk/extras/android/support/v7/appcompat/res/values/themes.xml sdk/extras/android/support/v7/appcompat/res/values/themes_base.xml 

to the res / values ​​/ folder in your project.

+1
source share

All Articles