1

我试图阅读我使用http://www.siegmann.nl/epublib/android的 epub 文件。我正在尝试链接中给出的相同示例,但我得到了java.lang.NoClassDefFoundError。我尽我所能。即使通过 adt、eclipse 进行更改,但我无法解决此问题。请调查一下并给我一些建议。

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

尽管我的代码与上面的链接相似,但我也提供了代码。

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);
        }
      }
}
4

3 回答 3

3

我通过添加另外两个 jar 文件解决了这个问题

slf4j-api 和 slf4j-simple。slf4j-android 依赖于我提到的库。

谢谢你的帮助。

于 2012-04-23T07:04:35.130 回答
1

我认为您忘记将 slf4j-android 库添加到您的项目中。如果您查看您提供的链接,它会说:

入门

  1. 从https://github.com/downloads/psiegman/epublib/epublib-core-latest.jar下载 epublib-core-latest.jar
  2. 下载 slf4j-android
  3. 将两者都添加到您的 android 项目中

确保这两个库都在您的构建路径上。

于 2012-04-20T11:07:24.337 回答
-1

只需在 Libs 文件夹中添加这两个提到的 jar。如果 Libs 文件夹不在项目结构中,请创建一个并添加这些 jar。错误会消失。

于 2013-01-19T21:55:09.317 回答