问题
When i start app in Android 4.1.2 there are no any exception but when i start app in Android 2.3.5 i get this exception:
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
Please help me about this.
This is my TabActivity code:
package com.russian.apps;
import 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;
}
}
回答1:
I think that's because you are using those features of android that are not available in 2.3.5 version without support library.
Follow below steps:-
Right click on project --> Select ANdroid tools --> Add Support library
then clean and build the project..
This will do the trick..
来源:https://stackoverflow.com/questions/16654015/java-lang-classnotfoundexception-on-working-app