AndroidPdfViewer: java.lang.IllegalStateException: Don't call load on a PDF View without recycling it first
I have a tab view wherein three tabs exists. All the tab has pdfview. Each tab loads different pdf file from the database. Whenever the downloaded file loads in the pdfview (all this is happening inside async task) the following error shows up and then the app crashes
java.lang.IllegalStateException: Don't call load on a PDF View without recycling it first
I am not sure what am I supposed to do!
class MyAsync extends AsyncTask<Void, Void, Void> {
PDFView pdfView;
public MyAsync(PDFView pdfView) {
this.pdfView = pdfView;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pd.setMessage("Uploading . . .");
pd.show();
pd.setCancelable(false);
}
@Override
protected Void doInBackground(Void... voids) {
publishProgress();
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
dataRef.child(dbs).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChild(root_child)) {
String url = dataSnapshot.child(root_child).getValue().toString();
StorageReference island = storage.getReferenceFromUrl(url);
final File file;
try {
file = File.createTempFile(file_name, "pdf");
island.getFile(file).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
yes_file(pdfView, tv1, tv2);
pdfView.fromFile(file).load();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getActivity(), "Upload unsuccessful", Toast.LENGTH_LONG).show();
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
pd.dismiss();
}
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 24 (5 by maintainers)
Issue should be fixed in 3.0.0-beta.5 version
@barteksc when are you planing to release 3.0.0-beta.5 version?
It was released few days ago
I added the line
pdfView.recycle();beforepdfView.fromFile(file).load();But still the problem persists.Not sure if this the right way to recycle! Pls help. I Am stuck