问题
I have tried to read a epub file for which im using http://www.siegmann.nl/epublib/android. Im trying the same sample which is given in the link, but im getting java.lang.NoClassDefFoundError . I tried all the way i can. Even by changing by adt,eclipse but i cant able to solve this issue. Please look into it and provide me some suggestions.
04-20 15:08:47.735: E/AndroidRuntime(4329): FATAL EXCEPTION: main
04-20 15:08:47.735: E/AndroidRuntime(4329): java.lang.ExceptionInInitializerError
04-20 15:08:47.735: E/AndroidRuntime(4329): at com.sample.pubreader.EPubReaderActivity.onCreate(EPubReaderActivity.java:30)
04-20 15:08:47.735: E/AndroidRuntime(4329): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
04-20 15:08:47.735: E/AndroidRuntime(4329): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
04-20 15:08:47.735: E/AndroidRuntime(4329): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
04-20 15:08:47.735: E/AndroidRuntime(4329): at android.app.ActivityThread.access$1500(ActivityThread.java:132)
04-20 15:08:47.735: E/AndroidRuntime(4329): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
04-20 15:08:47.735: E/AndroidRuntime(4329): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 15:08:47.735: E/AndroidRuntime(4329): at android.os.Looper.loop(Looper.java:143)
04-20 15:08:47.735: E/AndroidRuntime(4329): at android.app.ActivityThread.main(ActivityThread.java:4196)
04-20 15:08:47.735: E/AndroidRuntime(4329): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 15:08:47.735: E/AndroidRuntime(4329): at java.lang.reflect.Method.invoke(Method.java:507)
04-20 15:08:47.735: E/AndroidRuntime(4329): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-20 15:08:47.735: E/AndroidRuntime(4329): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-20 15:08:47.735: E/AndroidRuntime(4329): at dalvik.system.NativeStart.main(Native Method)
04-20 15:08:47.735: E/AndroidRuntime(4329): Caused by: java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
04-20 15:08:47.735: E/AndroidRuntime(4329): at nl.siegmann.epublib.epub.EpubReader.<clinit>(EpubReader.java:33)
04-20 15:08:47.735: E/AndroidRuntime(4329): ... 14 more
Eventhough my code is similar to the above link,Im providing the code also.
public class EPubReaderActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AssetManager assetManager = getAssets();
try {
// find InputStream for book
InputStream epubInputStream = assetManager
.open("sample.epub");
// Load Book from inputStream
Book book = (new EpubReader()).readEpub(epubInputStream);
// Log the book's authors
Log.i("epublib", "author(s): " + book.getMetadata().getAuthors());
// Log the book's title
Log.i("epublib", "title: " + book.getTitle());
// Log the book's coverimage property
Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage()
.getInputStream());
Log.i("epublib", "Coverimage is " + coverImage.getWidth() + " by "
+ coverImage.getHeight() + " pixels");
// Log the tale of contents
logTableOfContents(book.getTableOfContents().getTocReferences(), 0);
} catch (IOException e) {
Log.e("epublib", e.getMessage());
}
}
private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
if (tocReferences == null) {
return;
}
for (TOCReference tocReference : tocReferences) {
StringBuilder tocString = new StringBuilder();
for (int i = 0; i < depth; i++) {
tocString.append("\t");
}
tocString.append(tocReference.getTitle());
Log.i("epublib", tocString.toString());
logTableOfContents(tocReference.getChildren(), depth + 1);
}
}
}
回答1:
I solved the problem by adding the two another jar files
slf4j-api and slf4j-simple. The slf4j-android has the dependency on the libraries which i have mentioned.
Thanks for your help.
回答2:
I think you forgot to add the slf4j-android library to your project. If you look at the link you've supplied, it says:
Getting started
- Download epublib-core-latest.jar from https://github.com/downloads/psiegman/epublib/epublib-core-latest.jar
- Download slf4j-android
- Add both to your android project
Make sure both libraries are on your build path.
回答3:
Just Add those two mentioned jars in the Libs folder. If the Libs folder is not in project structure, create one and add those jars. The error will go away.
来源:https://stackoverflow.com/questions/10244462/ebook-reading-error