我想在 android 中构建和运行 epub 内容并引用 http://www.siegmann.nl/epublib/android 并尝试实现相同的内容,但我收到类似错误
02-01 10:08:15.726: D/dalvikvm(27839): Late-enabling CheckJNI
02-01 10:08:15.926: I/dalvikvm(27839): Could not find method org.slf4j.LoggerFactory.getLogger, referenced from method nl.siegmann.epublib.epub.EpubReader.<clinit>
02-01 10:08:15.926: W/dalvikvm(27839): VFY: unable to resolve static method 4251: Lorg/slf4j/LoggerFactory;.getLogger (Ljava/lang/Class;)Lorg/slf4j/Logger;
02-01 10:08:15.926: D/dalvikvm(27839): VFY: replacing opcode 0x71 at 0x0002
02-01 10:08:16.066: I/dalvikvm(27839): Could not find method org.slf4j.Logger.error, referenced from method nl.siegmann.epublib.epub.EpubReader.getPackageResourceHref
02-01 10:08:16.066: W/dalvikvm(27839): VFY: unable to resolve interface method 4249: Lorg/slf4j/Logger;.error (Ljava/lang/String;Ljava/lang/Throwable;)V
02-01 10:08:16.066: D/dalvikvm(27839): VFY: replacing opcode 0x72 at 0x0045
02-01 10:08:16.066: I/dalvikvm(27839): Could not find method org.slf4j.Logger.error, referenced from method nl.siegmann.epublib.epub.EpubReader.processPackageResource
02-01 10:08:16.066: W/dalvikvm(27839): VFY: unable to resolve interface method 4249: Lorg/slf4j/Logger;.error (Ljava/lang/String;Ljava/lang/Throwable;)V
02-01 10:08:16.066: D/dalvikvm(27839): VFY: replacing opcode 0x72 at 0x000f
02-01 10:08:16.066: W/dalvikvm(27839): Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lnl/siegmann/epublib/epub/EpubReader;
02-01 10:08:16.066: D/AndroidRuntime(27839): Shutting down VM
02-01 10:08:16.066: W/dalvikvm(27839): threadid=1: thread exiting with uncaught exception (group=0x41e99930)
02-01 10:08:16.066: E/AndroidRuntime(27839): FATAL EXCEPTION: main
02-01 10:08:16.066: E/AndroidRuntime(27839): java.lang.ExceptionInInitializerError
02-01 10:08:16.066: E/AndroidRuntime(27839): at com.example.epub2.MainActivity.onCreate(MainActivity.java:32)
02-01 10:08:16.066: E/AndroidRuntime(27839): at android.app.Activity.performCreate(Activity.java:5104)
02-01 10:08:16.066: E/AndroidRuntime(27839): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-01 10:08:16.066: E/AndroidRuntime(27839): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-01 10:08:16.066: E/AndroidRuntime(27839): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-01 10:08:16.066: E/AndroidRuntime(27839): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-01 10:08:16.066: E/AndroidRuntime(27839): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-01 10:08:16.066: E/AndroidRuntime(27839): at android.os.Handler.dispatchMessage(Handler.java:99)
02-01 10:08:16.066: E/AndroidRuntime(27839): at android.os.Looper.loop(Looper.java:137)
02-01 10:08:16.066: E/AndroidRuntime(27839): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-01 10:08:16.066: E/AndroidRuntime(27839): at java.lang.reflect.Method.invokeNative(Native Method)
02-01 10:08:16.066: E/AndroidRuntime(27839): at java.lang.reflect.Method.invoke(Method.java:511)
02-01 10:08:16.066: E/AndroidRuntime(27839): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-01 10:08:16.066: E/AndroidRuntime(27839): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-01 10:08:16.066: E/AndroidRuntime(27839): at dalvik.system.NativeStart.main(Native Method)
02-01 10:08:16.066: E/AndroidRuntime(27839): Caused by: java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
02-01 10:08:16.066: E/AndroidRuntime(27839): at nl.siegmann.epublib.epub.EpubReader.<clinit>(EpubReader.java:33)
我的代码是::
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AssetManager assetManager = getAssets();
try {
// find InputStream for book
InputStream is = getAssets().open("ww.epub");
Book book = new EpubReader().readEpub(is);
// Load Book from inputStream
// 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);
}
}
}
是的,正如他们提到的,我导入了两个 jar 库!!我没有找到解决方案,任何人都可以帮助我吗?
02-01 10:08:15.926: I/dalvikvm(27839): Could not find method org.slf4j.LoggerFactory.getLogger, referenced from method nl.siegmann.epublib.epub.EpubReader.<clinit>
此错误表明您的包未加载 JAR 文件。您必须在libs文件夹中添加两个jar文件并将它们附加到构建路径中