** I was recomended to use 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 new application and followed advice.
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 catch an error message on phone, when I try to run it.
Please tell me what I do wrong
info 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 of 1-7
http://i.stack.imgur.com/NTpP3.jpg
I've got it worked after moving "Android Private Libraries" and "Android Dependencies" to the top of the list in Order and Export in my application project. Also I dont have android-support-v7-appcompat in this list. And in the android-support-v7-appcompat project I dont have support jars in the Order and Export list, but "Android Private Libraries" is checked. Please, check also the links below:
Setting up ActionBarCompat support library in Eclipse
Implementing Action Bar using ActionBarCompat support library in Android
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With