使用actionbarsherlock库的Android ClassNotFoundException

时间:2013-09-03 01:35:02

标签: android actionbarsherlock

在尝试在模拟器上运行项目时,我一直收到classnotfoundexception。在发布此问题之前,我已经在这里查看过,我已经尝试将库添加到构建路径,清理/构建项目但仍然没有解决问题。

该项目是使用开源日历项目构建的。所以这个名字很奇怪,但对构建没有任何影响。

这是LogCat:

09-03 12:37:36.990: E/Trace(2272): error opening trace file: No such file or directory (2)
09-03 12:37:37.439: W/dalvikvm(2272): Unable to resolve superclass of Lcom/squareup/timessquare/sample/DashboardActivity; (453)
09-03 12:37:37.482: W/dalvikvm(2272): Link of class 'Lcom/squareup/timessquare/sample/DashboardActivity;' failed
09-03 12:37:37.482: D/AndroidRuntime(2272): Shutting down VM
09-03 12:37:37.482: W/dalvikvm(2272): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
09-03 12:37:37.540: E/AndroidRuntime(2272): FATAL EXCEPTION: main
09-03 12:37:37.540: E/AndroidRuntime(2272): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.squareup.timessquare.sample/com.squareup.timessquare.sample.DashboardActivity}: java.lang.ClassNotFoundException: com.squareup.timessquare.sample.DashboardActivity
09-03 12:37:37.540: E/AndroidRuntime(2272):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at android.os.Looper.loop(Looper.java:137)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at android.app.ActivityThread.main(ActivityThread.java:4745)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at java.lang.reflect.Method.invokeNative(Native Method)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at java.lang.reflect.Method.invoke(Method.java:511)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at dalvik.system.NativeStart.main(Native Method)
09-03 12:37:37.540: E/AndroidRuntime(2272): Caused by: java.lang.ClassNotFoundException: com.squareup.timessquare.sample.DashboardActivity
09-03 12:37:37.540: E/AndroidRuntime(2272):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
09-03 12:37:37.540: E/AndroidRuntime(2272):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)

这里是清单中声明的​​类:

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

        <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="17" />


    <application
        android:label="@string/app_name"
        android:icon="@drawable/supporticon"
        android:debuggable="true"
        android:supportsRtl="true">

        <activity
            android:name=".DashboardActivity"
            android:label="@string/app_name"
            android:configChanges="orientation|screenSize|keyboardHidden"
            >

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

这是课堂内容:

public class DashboardActivity extends SherlockFragmentActivity {

    ActionBar mActionBar;
    ViewPager mPager;
    Tab tab;

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

        // Activate the navigation mode tabs
        mActionBar = getSupportActionBar();
        mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        // Locate the view pager in dashboard.xml
        mPager = (ViewPager) findViewById(R.id.pager);

        // Activate the fragment manager
        FragmentManager fm = getSupportFragmentManager();

        // Capture view pager swipes
        ViewPager.SimpleOnPageChangeListener ViewPagerListener = new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                // Find the view pager position
                mActionBar.setSelectedNavigationItem(position);
            }
        };

        mPager.setOnPageChangeListener(ViewPagerListener);
        // Locate the adapter class
        ViewPagerAdapter viewpageradapter = new ViewPagerAdapter(fm);
        // Set the view pager adapter in ViewPager
        mPager.setAdapter(viewpageradapter);

        // Capture the button clicks
        ActionBar.TabListener tabListener = new ActionBar.TabListener() {

            @Override
            public void onTabUnselected(Tab tab, FragmentTransaction ft) {
                // Pass the position on tab click to view pager
                mPager.setCurrentItem(tab.getPosition());

            }

            @Override
            public void onTabSelected(Tab tab, FragmentTransaction ft) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onTabReselected(Tab tab, FragmentTransaction ft) {
                // TODO Auto-generated method stub

            }
        };

        // Create the first tab
        tab = mActionBar.newTab().setText("Support Tab")
                .setTabListener(tabListener);
        mActionBar.addTab(tab);

        // Create the second tab
        tab = mActionBar.newTab().setText("Students Tab")
                .setTabListener(tabListener);
        mActionBar.addTab(tab);

    }

}

我能想到的唯一问题是当我右键点击我的项目&gt;项目属性&gt; Android的actionbarsherlock引用旁边有一个红叉。即使我的课程中没有错误,我已经使用过该库,但我不确定这是否与它有任何关系。

任何帮助将不胜感激,谢谢。

1 个答案:

答案 0 :(得分:0)

  

我能想到的唯一问题是当我右键点击我的时候   项目&gt;项目属性&gt; Android的actionbarsherlock参考   旁边有一个红十字。即使我没有错误   我使用过这个库的课程,我不确定这有什么用   与它有关。

是的,这肯定与它有关。这意味着您的项目找不到jar文件或lib项目的位置。

在项目属性页面中的该条目上,按下编辑按钮并再次导航到jar文件/ lib项目文件夹。只有当红色x变为绿色检查时,您才能正确运行程序。