我是Android的首次亮相,但遇到此错误
E / libEGL:validate_display:99错误3008(EGL_BAD_DISPLAY)
在调试我的应用程序时。我正在尝试使用.epub3
从资产中读取Webview
文件,但页面空白。
注意:我正在使用两个库:slf4j
和epublib-core
。
这是MainActivity
类:
webView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
try {
Book book = (new EpubReader( )).readEpub(new FileInputStream("adventures.epub"));
String baseUrl = "file:///android_asset/";
String data = new String(book.getContents( ).get(2).getData( ));
webView.loadDataWithBaseURL(baseUrl, data, "text/html", "UTF-8", null);
} catch (IOException e) {
e.printStackTrace( );
}
AssetManager assetManager = getAssets( );
try {
// find InputStream for book
InputStream epubInputStream = assetManager
.open("adventures.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( ));
}
}
/**
* Recursively Log the Table of Contents
*
* @param tocReferences
* @param depth
*/
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);
}
}}