Ошибка:java.lang.NoClassDefFoundError
Извините, это повторяющийся вопрос, но я еще не нашел свой ответ. Чтобы сделать FileChooser в моем приложении для Android, я использовал это. Поэтому я добавил 2 jar-файла в свой путь Свойства-> Java Build(один из них android-support-v4.jar
а другая библиотека ручной работы (afilechooser
)), но когда дело доходит до запуска я сталкиваюсь с этими ошибками в onResume()
метод.
1-Возможно ли, что есть проблемы с библиотеками?
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)
,,,
3 ответа
Пожалуйста, замените файл android-support-v4.jar. и ставь ActivityNot Found Exception.
Intent target = FileUtils.createGetContentIntent();
Intent intent = Intent.createChooser(
target, getString(R.string.chooser_title));
try {
startActivityForResult(intent, REQUEST_CODE);
} catch (ActivityNotFoundException e) {
}
Вы должны импортировать библиотеку как существующий проект Android в рабочую область Eclipse. Проверьте в свойствах, что он определен как библиотека.
Затем вы должны импортировать его в свой проект. Это делается в Свойствах => Android => Добавить (в разделе библиотеки). Выберите библиотеку, и тогда она должна работать
В Затмении:
- Щелкните правой кнопкой мыши по вашему проекту
- Выберите "Свойства" -> "Путь сборки Java" -> "Порядок и экспорт".
- Проверьте Android-библиотеки и нажмите кнопку ОК.