无法从ActionBarSherlock项目调用我的类方法?知道为什么吗?

时间:2014-02-19 19:15:47

标签: java android user-interface android-actionbar actionbarsherlock

我已在网络上设置ActionBarSherlock观看教程。我能够在我的应用程序中成功运行ActionBarSherlock但是每当我尝试从我的类调用代码时遇到一个不同的问题,应用程序崩溃抛出java.lang.NoClassDefFoundError异常。

如果我从项目中删除ActionBarSherlock的依赖项,则相同的应用程序可以成功运行。

以下是我每次尝试在我写的类中调用方法时得到的堆栈跟踪:

02-20 00:35:02.909: E/AndroidRuntime(32191): FATAL EXCEPTION: main
02-20 00:35:02.909: E/AndroidRuntime(32191): java.lang.NoClassDefFoundError: com.example.sample.Manager
02-20 00:35:02.909: E/AndroidRuntime(32191):    at com.jakhar.actionbar.MainActivity.onCreate(MainActivity.java:27)
02-20 00:35:02.909: E/AndroidRuntime(32191):    at android.app.Activity.performCreate(Activity.java:5255)
02-20 00:35:02.909: E/AndroidRuntime(32191):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
02-20 00:35:02.909: E/AndroidRuntime(32191):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2213)
02-20 00:35:02.909: E/AndroidRuntime(32191):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
02-20 00:35:02.909: E/AndroidRuntime(32191):    at android.app.ActivityThread.access$700(ActivityThread.java:154)
02-20 00:35:02.909: E/AndroidRuntime(32191):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
02-20 00:35:02.909: E/AndroidRuntime(32191):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-20 00:35:02.909: E/AndroidRuntime(32191):    at android.os.Looper.loop(Looper.java:137)
02-20 00:35:02.909: E/AndroidRuntime(32191):    at android.app.ActivityThread.main(ActivityThread.java:5306)
02-20 00:35:02.909: E/AndroidRuntime(32191):    at java.lang.reflect.Method.invokeNative(Native Method)
02-20 00:35:02.909: E/AndroidRuntime(32191):    at java.lang.reflect.Method.invoke(Method.java:511)
02-20 00:35:02.909: E/AndroidRuntime(32191):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
02-20 00:35:02.909: E/AndroidRuntime(32191):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
02-20 00:35:02.909: E/AndroidRuntime(32191):    at dalvik.system.NativeStart.main(Native Method)

这是我的活动类:

public class MainActivity extends SherlockActivity implements SearchView.OnQueryTextListener,
SearchView.OnSuggestionListener {

    private Object mSuggestionsAdapter;

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

        //#########At this line my code crashes.###########//
        Manager.startManager(getApplicationContext);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        boolean isLight = true;

        //Create the search view
        SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());
        searchView.setQueryHint("Search in MyWord¦");
        searchView.setOnQueryTextListener(this);
        searchView.setOnSuggestionListener(this);

//        if (mSuggestionsAdapter == null) {
//            MatrixCursor cursor = new MatrixCursor(COLUMNS);
//            cursor.addRow(new String[]{"1", "'Murica"});
//            cursor.addRow(new String[]{"2", "Canada"});
//            cursor.addRow(new String[]{"3", "Denmark"});
//            mSuggestionsAdapter = new SuggestionsAdapter(getSupportActionBar().getThemedContext(), cursor);
//        }

//        searchView.setSuggestionsAdapter(mSuggestionsAdapter);

        menu.add("Search")
            .setIcon(isLight ? R.drawable.abs__ic_search_api_holo_light : R.drawable.abs__ic_search)
            .setActionView(searchView)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);


//     MenuInflater inflater = getSupportMenuInflater();
//     inflater.inflate(R.menu.main_action_bar, menu);
       return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        createSearchView();

       // Handle item selection
       switch (item.getItemId()) {
          case R.id.action_search:
             // do s.th.
             return true;

          default:
             return super.onOptionsItemSelected(item);
       }
    }


    private void createSearchView() {
        //Create the search view
        SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());
        searchView.setQueryHint("Search for countries…");
        searchView.setOnQueryTextListener(this);
        searchView.setOnSuggestionListener(this);
        String[] COLUMNS = {"A","B","C"};

//        if (mSuggestionsAdapter == null) {
//            MatrixCursor cursor = new MatrixCursor(COLUMNS);
//            cursor.addRow(new String[]{"1", "'Murica"});
//            cursor.addRow(new String[]{"2", "Canada"});
//            cursor.addRow(new String[]{"3", "Denmark"});
//            //mSuggestionsAdapter = new SuggestionsAdapter(getSupportActionBar().getThemedContext(), cursor);
//        }

    }

    public void clickMe(View view)
    {
        Intent intent = new Intent(MainActivity.this, SecondActivity.class);
        startActivity(intent);
    }

    @Override
    public boolean onSuggestionSelect(int position) {
        // TODO Auto-generated method stub
        return false;
    }


    @Override
    public boolean onSuggestionClick(int position) {
        // TODO Auto-generated method stub
        return false;
    }


    @Override
    public boolean onQueryTextSubmit(String query) {
        // TODO Auto-generated method stub
        return false;
    }


    @Override
    public boolean onQueryTextChange(String newText) {
        // TODO Auto-generated method stub
        return false;
    }
}

这是我的AndroidManifest.xml文件。

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Sherlock.Light.DarkActionBar">
        <activity
            android:name="com.jakhar.actionbar.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.jakhar.actionbar.SecondActivity"></activity>
    </application>

</manifest>

0 个答案:

没有答案