[英]Error:java.lang.NoClassDefFoundError
抱歉,这是一个重复性的问题,但是我还没有找到答案。 为了在我的Android应用程序中创建FileChooser,我使用了this 。 所以我在Properties-> Java Build路径中添加了2个jar文件(其中一个是android-support-v4.jar
,另一个是手工库( afilechooser
)),但是当运行时,我遇到这些错误onResume()
方法。
1-libs是否有问题?
2-您的解决方案是什么?
3- FileChooserActivity是否有问题?
该类是:
public class FileChooserActivity extends FragmentActivity implements
OnBackStackChangedListener {
public static final String PATH = "path";
public static final String EXTERNAL_BASE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath();
private FragmentManager mFragmentManager;
private BroadcastReceiver mStorageListener = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, R.string.storage_removed, Toast.LENGTH_LONG).show();
finishWithResult(null);
}
};
private String mPath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chooser);
mFragmentManager = getSupportFragmentManager();
mFragmentManager.addOnBackStackChangedListener(this);
if (savedInstanceState == null) {
mPath = EXTERNAL_BASE_PATH;
addFragment(mPath);
} else {
mPath = savedInstanceState.getString(PATH);
}
setTitle(mPath);
}
@Override
protected void onPause() {
super.onPause();
unregisterStorageListener();
}
@Override
protected void onResume() {
super.onResume();
registerStorageListener();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(PATH, mPath);
}
@Override
public void onBackStackChanged() {
mPath = EXTERNAL_BASE_PATH;
int count = mFragmentManager.getBackStackEntryCount();
if (count > 0) {
BackStackEntry fragment = mFragmentManager
.getBackStackEntryAt(count - 1);
mPath = fragment.getName();
}
setTitle(mPath);
}
/**
* Add the initial Fragment with given path.
*
* @param path The absolute path of the file (directory) to display.
*/
private void addFragment(String path) {
FileListFragment explorerFragment = FileListFragment.newInstance(mPath);
mFragmentManager.beginTransaction()
.add(R.id.explorer_fragment, explorerFragment).commit();
}
/**
* "Replace" the existing Fragment with a new one using given path.
* We're really adding a Fragment to the back stack.
*
* @param path The absolute path of the file (directory) to display.
*/
private void replaceFragment(String path) {
FileListFragment explorerFragment = FileListFragment.newInstance(path);
mFragmentManager.beginTransaction()
.replace(R.id.explorer_fragment, explorerFragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.addToBackStack(path).commit();
}
/**
* Finish this Activity with a result code and URI of the selected file.
*
* @param file The file selected.
*/
private void finishWithResult(File file) {
if (file != null) {
Uri uri = Uri.fromFile(file);
setResult(RESULT_OK, new Intent().setData(uri));
finish();
} else {
setResult(RESULT_CANCELED);
finish();
}
}
/**
* Called when the user selects a File
*
* @param file The file that was selected
*/
protected void onFileSelected(File file) {
if (file != null) {
mPath = file.getAbsolutePath();
if (file.isDirectory()) {
replaceFragment(mPath);
} else {
finishWithResult(file);
}
} else {
Toast.makeText(FileChooserActivity.this, R.string.error_selecting_file, Toast.LENGTH_SHORT).show();
}
}
/**
* Register the external storage BroadcastReceiver.
*/
private void registerStorageListener() {
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_REMOVED);
registerReceiver(mStorageListener, filter);
}
/**
* Unregister the external storage BroadcastReceiver.
*/
private void unregisterStorageListener() {
unregisterReceiver(mStorageListener);
}
}
错误是:
06-04 04:30:57.547: E/AndroidRuntime(605): FATAL EXCEPTION: main
06-04 04:30:57.547: E/AndroidRuntime(605): java.lang.NoClassDefFoundError: com.ipaulpro.afilechooser.R$layout
06-04 04:30:57.547: E/AndroidRuntime(605): at com.ipaulpro.afilechooser.FileChooserActivity.onCreate(FileChooserActivity.java:65)
06-04 04:30:57.547: E/AndroidRuntime(605): at android.app.Activity.performCreate(Activity.java:5104)
06-04 04:30:57.547: E/AndroidRuntime(605): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-04 04:30:57.547: E/AndroidRuntime(605): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
。 。 。
在Eclipse中:
您应该将该库作为现有的Android项目导入到Eclipse工作区中。 签入定义为库的属性。
然后,您必须将其导入项目中。 这是在Properties => Android => Add(在库部分)中完成的。 选择库,然后它应该可以工作
请替换android-support-v4.jar文件。 并将ActivityNot Found异常。
Intent target = FileUtils.createGetContentIntent();
Intent intent = Intent.createChooser(
target, getString(R.string.chooser_title));
try {
startActivityForResult(intent, REQUEST_CODE);
} catch (ActivityNotFoundException e) {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.