我正在尝试实现一个程序来读取 pdf 文件,但是当我这样做时,我无法在第一次和第二次显示页面时显示几个带有重叠单词的页面。我不明白出了什么问题任何人都可以建议我该怎么办?
public class MainActivity extends ListActivity {
String[] pdflist;
File[] imagelist;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
File images = Environment.getExternalStorageDirectory();
System.out.println("images" + images);
imagelist = images.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return ((name.endsWith(".pdf")));
}
});
pdflist = new String[imagelist.length];
for (int i = 0; i < imagelist.length; i++) {
pdflist[i] = imagelist[i].getName();
}
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, pdflist));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String path = imagelist[(int) id].getAbsolutePath();
openPdfIntent(path);
}
private void openPdfIntent(String path) {
try {
final Intent intent = new Intent(MainActivity.this, Second.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
日志详细信息:
02-04 13:14:09.232: E/PDFVIEWER(1123): null
02-04 13:14:09.232: E/PDFVIEWER(1123): java.nio.BufferUnderflowException
02-04 13:14:09.232: E/PDFVIEWER(1123): at java.nio.Buffer.checkGetBounds(Buffer.java:177)
02-04 13:14:09.232: E/PDFVIEWER(1123): at java.nio.DirectByteBuffer.get(DirectByteBuffer.java:41)
02-04 13:14:09.232: E/PDFVIEWER(1123): at java.nio.MappedByteBufferAdapter.get(MappedByteBufferAdapter.java:144)
02-04 13:14:09.232: E/PDFVIEWER(1123): at java.nio.ByteBuffer.get(ByteBuffer.java:384)
02-04 13:14:09.232: E/PDFVIEWER(1123): at net.sf.andpdf.nio.NioByteBuffer.get(NioByteBuffer.java:99)
02-04 13:14:09.232: E/PDFVIEWER(1123): at com.sun.pdfview.decode.FlateDecode.decode(FlateDecode.java:68)
02-04 13:14:09.232: E/PDFVIEWER(1123): at com.sun.pdfview.decode.PDFDecoder.decodeStream(PDFDecoder.java:92)
02-04 13:14:09.232: E/PDFVIEWER(1123): at com.sun.pdfview.PDFObject.decodeStream(PDFObject.java:334)
02-04 13:14:09.232: E/PDFVIEWER(1123): at com.sun.pdfview.PDFObject.getStreamBuffer(PDFObject.java:307)
02-04 13:14:09.232: E/PDFVIEWER(1123): at com.sun.pdfview.PDFFile.dereference(PDFFile.java:272)
02-04 13:14:09.232: E/PDFVIEWER(1123): at com.sun.pdfview.PDFObject.dereference(PDFObject.java:686)
02-04 13:14:09.232: E/PDFVIEWER(1123): at com.sun.pdfview.PDFObject.getDictRef(PDFObject.java:508)
02-04 13:14:09.232: E/PDFVIEWER(1123): at com.sun.pdfview.PDFFile.findPage(PDFFile.java:1696)
02-04 13:14:09.232: E/PDFVIEWER(1123): at com.sun.pdfview.PDFFile.getPage(PDFFile.java:1569)
02-04 13:14:09.232: E/PDFVIEWER(1123): at net.sf.andpdf.pdfviewer.PdfViewerActivity.showPage(PdfViewerActivity.java:779)
02-04 13:14:09.232: E/PDFVIEWER(1123): at net.sf.andpdf.pdfviewer.PdfViewerActivity.access$12(PdfViewerActivity.java:769)
02-04 13:14:09.232: E/PDFVIEWER(1123): at net.sf.andpdf.pdfviewer.PdfViewerActivity$3.run(PdfViewerActivity.java:259)
02-04 13:14:09.232: E/PDFVIEWER(1123): at java.lang.Thread.run(Thread.java:856)
二等:
package com.syntel.pdfviewer;
import android.os.Bundle;
import net.sf.andpdf.pdfviewer.PdfViewerActivity;
public class Second extends PdfViewerActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
public int getPreviousPageImageResource() {
return R.drawable.ic_launcher;
}
public int getNextPageImageResource() {
return R.drawable.ic_launcher;
}
public int getZoomInImageResource() {
return R.drawable.ic_launcher;
}
public int getZoomOutImageResource() {
return R.drawable.ic_launcher;
}
@Override
public int getPdfPageNumberEditField() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getPdfPageNumberResource() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getPdfPasswordEditField() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getPdfPasswordExitButton() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getPdfPasswordLayoutResource() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getPdfPasswordOkButton() {
// TODO Auto-generated method stub
return 0;
}
/*
* public int getPdfPasswordLayoutResource() { return R.layout.ic_launcher;
* }
*
* public int getPdfPageNumberResource() { return
* R.layout.dialog_pagenumber; }
*
* public int getPdfPasswordEditField() { return R.id.etPassword; }
*
* public int getPdfPasswordOkButton() { return R.id.btOK; }
*
* public int getPdfPasswordExitButton() { return R.id.btExit; }
*
* public int getPdfPageNumberEditField() { return R.id.pagenum_edit; }
*/
}