简体   繁体   English

使用actionbarsherlock库的Android ClassNotFoundException

[英]Android ClassNotFoundException using actionbarsherlock library

I keep getting the classnotfoundexception when trying to run my project on an emulator. 尝试在模拟器上运行项目时,我不断收到classnotfoundexception。 I have looked around on here before posting this question, I have tried adding libraries to the build path, cleaning / building the project but still hasn't solved the issue. 在发布此问题之前,我已经环顾四周,我曾尝试将库添加到构建路径,清理/构建项目,但仍未解决问题。

The project was built from using an open source calendar project. 该项目是使用开源日历项目构建的。 So the name is weird, but doesn't have any affect on the build. 所以这个名字很奇怪,但是对构建没有任何影响。

Here's the LogCat: 这是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)

And here's the class declared in the manifest: 这是清单中声明的​​类:

<?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>

Here's the class content: 这是课程内容:

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);

    }

}

The only issues I can think of is that when I right click on my project > project properties > Android the actionbarsherlock reference has a red cross beside it. 我能想到的唯一问题是,当我右键单击我的项目>项目属性> Android时,actionbarsherlock参考旁边有一个红叉。 Even though there are no errors in my classes where I've used the library, I'm not sure if this has anything to do with it. 即使在使用该库的类中没有错误,我也不知道这是否与它有关。

Any help would be appreciated, thanks. 任何帮助,将不胜感激,谢谢。

The only issues I can think of is that when I right click on my project > project properties > Android the actionbarsherlock reference has a red cross beside it. 我能想到的唯一问题是,当我右键单击我的项目>项目属性> Android时,actionbarsherlock参考旁边有一个红叉。 Even though there are no errors in my classes where I've used the library, I'm not sure if this has anything to do with it. 即使在使用该库的类中没有错误,我也不知道这是否与它有关。

Yes this definitely has something to do with it. 是的,这肯定与它有关。 This means that your project cannot find the place of your jar file, or lib project. 这意味着您的项目无法找到jar文件或lib项目的位置。

On that entry in the project properties page press the edit button and navigate to the jar file/ lib project folder again. 在项目属性页面的该条目上,按编辑按钮,然后再次导航到jar文件/ lib项目文件夹。 Only when that red x turns into a green check will you be able to run your program correctly. 只有当红色x变成绿色复选标记时,您才能正确运行程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM