您好!
我需要从epub-file
中提取资源,并将其用于此ebublib
。它适用于很多文件,但有时我得到NullPointerException.
有我的代码:
InputStream bookInputStream = new BufferedInputStream(new FileInputStream(bookFile));
Book book = new EpubReader().readEpub(bookInputStream);
Collection<Resource> clrst = book.getResources().getAll();
int all = clrst.size();
int curr = 0;
for (Resource rs : clrst) {
Log.d(TAG, ++curr + "/" + all + " | " + rs.getSize());
builder.setProgress(all, curr, false);
notificationManager.notify(1, builder.build());
File oppath1 = new File(directory + File.separator + rs.getHref());
oppath1.getParentFile().mkdirs();
oppath1.createNewFile();
FileOutputStream fos1 = new FileOutputStream(oppath1);
fos1.write(rs.getData());
fos1.close();
}
还有堆栈跟踪:
10-12 11:23:29.668 24731-25088/ru.intuit.nou I/AndroidLoggerFactory﹕ Logger name 'nl.siegmann.epublib.epub.EpubProcessorSupport' exceeds maximum length of 23 characters, using 'n*.s*.e*.e*.EpubProces*' instead. 10-12 11:23:29.684 24731-25088/ru.intuit.nou I/AndroidLoggerFactory﹕ Logger name 'nl.siegmann.epublib.epub.PackageDocumentReader' exceeds maximum length of 23 characters, using 'n*.s*.e*.e*.PackageDoc*' instead. 10-12 11:23:29.692 24731-25088/ru.intuit.nou E/n*.s*.e*.e*.EpubReader﹕ null
java.lang.NullPointerException
at nl.siegmann.epublib.epub.PackageDocumentReader.read(PackageDocumentReader.java:51)
at nl.siegmann.epublib.epub.EpubReader.processPackageResource(EpubReader.java:119)
at nl.siegmann.epublib.epub.EpubReader.readEpub(EpubReader.java:97)
at nl.siegmann.epublib.epub.EpubReader.readEpub(EpubReader.java:53)
at nl.siegmann.epublib.epub.EpubReader.readEpub(EpubReader.java:37)
at ru.intuit.nou.fragments.CourseInfoFragment$DownloadTask.downloadResources(CourseInfoFragment.java:1269)
at ru.intuit.nou.fragments.CourseInfoFragment$DownloadTask.doInBackground(CourseInfoFragment.java:1140)
at ru.intuit.nou.fragments.CourseInfoFragment$DownloadTask.doInBackground(CourseInfoFragment.java:1047)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856) 10-12 11:23:29.692 24731-25088/ru.intuit.nou I/AndroidLoggerFactory﹕ Logger name 'nl.siegmann.epublib.epub.NCXDocument' exceeds maximum length of 23 characters, using 'n*.s*.e*.e*.NCXDocument' instead. 10-12 11:23:29.692 24731-25088/ru.intuit.nou E/n*.s*.e*.e*.NCXDocument﹕ Book does not contain a table of contents file
我不知道为什么它不适用于某些epub文件,我会很乐意提供任何帮助。提前谢谢!