gpt4 book ai didi

java - 滚动条并导入 com.github.barteksc.pdfviewer.ScrollBar;是错误,PDF 查看器也会崩溃

转载 作者:太空宇宙 更新时间:2023-11-04 10:45:58 33 4
gpt4 key购买 nike

ScrollBarimport com.github.barteksc.pdfviewer.ScrollBar; 不起作用

此外,当我在设备上运行然后点击我想查看的 pdf 时,应用程序崩溃了。

This is Screenshot where the errors i cant solve

This activity list the pdf file in the listview from phone Directory Storage

请问有人可以帮助我吗?

我对编程很陌生错误让我无法休眠

以下是代码:

    import com.example.mcphil.avastus.R;
import com.github.barteksc.pdfviewer.ScrollBar;
import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
import java.io.File;

public class PDF_Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pdf_);


//PDFVIEW SHALL DISPLAY OUR PDFS
PDFView pdfView= (PDFView) findViewById(R.id.pdfView);
//SCROLLBAR TO ENABLE SCROLLING
ScrollBar scrollBar1 = (ScrollBar) findViewById(R.id.scrollBar);
pdfView.setScrollBar(scrollBar1);
//VERTICAL SCROLLING
scrollBar1.setHorizontal(false);
//SACRIFICE MEMORY FOR QUALITY
pdfView.useBestQuality(true)

//UNPACK OUR DATA FROM INTENT
Intent i=this.getIntent();
String path=i.getExtras().getString("PATH");

//GET THE PDF FILE
File file=new File(path);

if(file.canRead())
{
//LOAD IT
pdfView.fromFile(file).defaultPage(1).onLoad(new OnLoadCompleteListener() {
@Override
public void loadComplete(int nbPages) {
Toast.makeText(PDF_Activity.this, String.valueOf(nbPages), Toast.LENGTH_LONG).show();
}
}).load();
}
}
}

如何将上面的代码与此代码连接起来?

import java.io.File;
import java.util.ArrayList;

public class DocumentActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_document);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

final ListView lv= (ListView) findViewById(R.id.lv);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
lv.setAdapter(new CustomAdapter(DocumentActivity.this,getPDFs()));

}
});
}

private ArrayList<PDFDoc> getPDFs()

{
ArrayList<PDFDoc> pdfDocs=new ArrayList<>();
//TARGET FOLDER
File downloadsFolder= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
//may results crash
File documentsFolder= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
PDFDoc pdfDoc,pdfDoc2;

if(downloadsFolder.exists())
{
//GET ALL FILES IN DOWNLOAD FOLDER
File[] files=downloadsFolder.listFiles();

//LOOP THRU THOSE FILES GETTING NAME AND URI
for (int i = 0; i < files.length; i++) {
File file = files[i];

if (file.getPath().endsWith("pdf")) {
pdfDoc = new PDFDoc();
pdfDoc.setName(file.getName());
pdfDoc.setPath(file.getAbsolutePath());
pdfDocs.add(pdfDoc);
}
}
}
// may result crash
if(documentsFolder.exists())
{
//GET ALL FILES IN DOWNLOAD FOLDER
File[] files2=documentsFolder.listFiles();

//LOOP THRU THOSE FILES GETTING NAME AND URI
for(int i = 0; i < files2.length; i++) {
File file = files2[i];

if (file.getPath().endsWith("pdf")) {
pdfDoc2 = new PDFDoc();
pdfDoc2.setName(file.getName());
pdfDoc2.setPath(file.getAbsolutePath());

pdfDocs.add(pdfDoc2);
}
}
}
return pdfDocs;
}
}

感谢您的帮助!我很匆忙 T.T

最佳答案

在 Github “AndroidPdfViewerV1/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/ScrollBar.java”

解决了这个错误

关于java - 滚动条并导入 com.github.barteksc.pdfviewer.ScrollBar;是错误,PDF 查看器也会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48414816/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com