My MainActivity class throws java.lang.ClassNotFoundException when extends ActionBarActivity

巧了我就是萌 提交于 2019-11-30 20:44:04

问题


I followed the instructions indicated in other threads on how to import external libraries, but after importing android-support-v7-appcompat.jar into the Referenced Libraries of my Android project (in ADT v.22.0.5) I get java.lang.ClassNotFoundException:

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

public class MainActivity extends ActionBarActivity {

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

        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        }
}

Can someone please shed some light?


回答1:


Go the "Java Build Path" -> Order and export -> check all checkboxes -> clean -> build -> run




回答2:


You must add the class path to your new library.

You can see a file named .classpath, specify the path to your new library.

<classpathentry kind="lib" path="<path to your .jar file>"/>



回答3:


I fixed it following these instructions:

  1. How to set up ActionBarCompat in Eclipse

  2. How to implement Action Bar using ActionBarCompat



来源:https://stackoverflow.com/questions/18565956/my-mainactivity-class-throws-java-lang-classnotfoundexception-when-extends-actio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!