0

当我在 Android 4.1.2 中启动应用程序时没有任何异常,但是当我在 Android 2.3.5 中启动应用程序时出现此异常:

    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.russian.apps/com.russian.apps.TabActivity}: java.lang.ClassNotFoundException: com.russian.apps.TabActivity in loader dalvik.system.PathClassLoader[/data/app/com.russian.apps-1.apk]
 05-20 16:23:57.668: E/AndroidRuntime(608):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at android.os.Handler.dispatchMessage(Handler.java:99)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at android.os.Looper.loop(Looper.java:123)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at android.app.ActivityThread.main(ActivityThread.java:3683)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at java.lang.reflect.Method.invokeNative(Native Method)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at java.lang.reflect.Method.invoke(Method.java:507)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at dalvik.system.NativeStart.main(Native Method)
 05-20 16:23:57.668: E/AndroidRuntime(608): Caused by: java.lang.ClassNotFoundException: com.russian.apps.TabActivity in loader dalvik.system.PathClassLoader[/data/app/com.russian.apps-1.apk]
 05-20 16:23:57.668: E/AndroidRuntime(608):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
 05-20 16:23:57.668: E/AndroidRuntime(608):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
 05-20 16:23:57.668: E/AndroidRuntime(608):     ... 11 more

请帮我解决这个问题。

这是我的 TabActivity 代码:
package com.russian.apps;导入 java.util.List;

    import com.viewpagerindicator.TabPageIndicator;



    import android.os.Bundle;
    import android.provider.SearchRecentSuggestions;
    import android.annotation.SuppressLint;
    import android.app.Activity;
    import android.app.SearchManager;
    import android.app.SearchableInfo;
    import android.content.Context;
    import android.content.pm.ApplicationInfo;
    import android.content.pm.PackageManager;
    import android.hardware.Camera;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentActivity;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentPagerAdapter;
    import android.support.v4.view.ViewPager;
    import android.util.Log;
    import android.view.Menu;
    import android.view.MenuInflater;
    import android.view.MenuItem;
    import android.view.Window;
    import android.widget.SearchView;
    import android.widget.SearchView.OnQueryTextListener;
    import android.widget.TextView;


    public class TabActivity extends FragmentActivity  implements SearchView.OnQueryTextListener{
        private static final String[] CONTENT = new String[] { "Top ", "New Added","Downloaded" };
        private TextView mStatusView;
        private SearchView mSearchView;
        private SearchRecentSuggestions suggestions;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
            setContentView(R.layout.simple_tabs);

            mStatusView = (TextView) findViewById(R.id.status_text);

            final PackageManager pm = getPackageManager();
            //get a list of installed apps.
            List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);



            for (ApplicationInfo packageInfo : packages) {
                Log.d("TAG", "Installed package :" + packageInfo.packageName);
                Log.d("TAG", "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); 
            }


            FragmentPagerAdapter adapter = new GoogleMusicAdapter(getSupportFragmentManager());

            ViewPager pager = (ViewPager)findViewById(R.id.pager);
            pager.setAdapter(adapter);

            TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator);
            indicator.setViewPager(pager);
        }

        class GoogleMusicAdapter extends FragmentPagerAdapter {
            public GoogleMusicAdapter(FragmentManager fm) {
                super(fm);
            }

            @Override
            public Fragment getItem(int position) {
                return TestFragment.newInstance(CONTENT[position % CONTENT.length]);
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return CONTENT[position % CONTENT.length].toUpperCase();
            }

            @Override
            public int getCount() {
              return CONTENT.length;
            }
        }

        @SuppressLint("NewApi")
        @Override
          public boolean onCreateOptionsMenu(Menu menu) {
              super.onCreateOptionsMenu(menu);

              MenuInflater inflater = getMenuInflater();
              inflater.inflate(R.menu.main, menu);
              MenuItem searchItem = menu.findItem(R.id.action_search);



              mSearchView = (SearchView) searchItem.getActionView();
              setupSearchView(searchItem);

              return true;
          }


        @SuppressLint({ "NewApi", "NewApi" })
        private void setupSearchView(MenuItem searchItem) {

              if (isAlwaysExpanded()) {
                  mSearchView.setIconifiedByDefault(true);
              } else {
                  searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM
                          | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
              }


              SearchManager searchManager = (SearchManager) (SearchManager)getBaseContext().getApplicationContext().getSystemService(Context.SEARCH_SERVICE);
              if (searchManager != null) {
                  List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();

                  SearchableInfo info = searchManager.getSearchableInfo(getComponentName());



                  for (SearchableInfo inf : searchables) {
                    Log.e("nese",inf.getSuggestAuthority());

                      if (inf.getSuggestAuthority() != null
                              && inf.getSuggestAuthority().contains("l;")) {
                          info = inf;
                      }
                  }
                  mSearchView.setSearchableInfo(info);
              }


              mSearchView.setOnQueryTextListener((OnQueryTextListener) this);
          }

          public boolean onQueryTextChange(String newText) {
              mStatusView.setText("Query = " + newText);
              return false;
          }

          public boolean onQueryTextSubmit(String query) {
              mStatusView.setText("Query = " + query + " : submitted");

           //   suggestions.saveRecentQuery(query, null);


              return false;
          }

          public boolean onClose() {
              mStatusView.setText("Closed!");
              return false;
          }

          protected boolean isAlwaysExpanded() {
              return false;
          }
    }
4

1 回答 1

2

我认为那是因为您正在使用 2.3.5 版本中没有支持库的 android 的那些功能。

请按照以下步骤操作:-

右键单击项目-->选择ANdroid工具-->添加支持库

然后清理并构建项目..

这会成功的..

于 2013-05-20T16:38:29.493 回答