Open MayurDev opened 5 years ago
Even I am getting the same error on this
Same issue here
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Thread.isAlive()' on a null object reference
at com.github.barteksc.pdfviewer.PDFView.loadComplete(PDFView.java:756)
at com.github.barteksc.pdfviewer.DecodingAsyncTask.onPostExecute(DecodingAsyncTask.java:80)
at com.github.barteksc.pdfviewer.DecodingAsyncTask.onPostExecute(DecodingAsyncTask.java:27)
I am also facing the same issue
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.HandlerThread.isAlive()' on a null object reference
at com.github.barteksc.pdfviewer.PDFView.loadComplete(PDFView.java:756)
Duplicate of #834.
Any update on this issue?
I'm experiencing this as well.
Not all devices are experiencing this issue
@barteksc Please when is this issue going to be fixed
same here
I make this solution in few seconds after searching .. i was getting this error
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.HandlerThread.isAlive()' on a null object reference at com.github.barteksc.pdfviewer.PDFView.loadComplete(PDFView.java:756) at com.github.barteksc.pdfviewer.DecodingAsyncTask.onPostExecute(DecodingAsyncTask.java:80) at com.github.barteksc.pdfviewer.DecodingAsyncTask.onPostExecute(DecodingAsyncTask.java:27)
Hi i solved this problem you need to do declare your sync task variable publicly like this you need to cancel ask task on backcrossed and on destroy but only if it is not null this crash is coming you start async task and when the will get late to load you go back to the list of files and your app crashes on pdf files activity simple do this thing please do not forget to cancel async task that is creating this issue in on destroy and on backcrossed .
`
public void onBackPressed() {
super.onBackPressed();
if (mtask!=null)
mtask.cancel(true);
}
@Override
protected void onDestroy() {
if (mtask!=null)
mtask.cancel(true);
super.onDestroy();
}
ViewFiles mtask;
private File dummyFile;
private class ViewFiles extends AsyncTask<Void,Void,Void>{
@Override
protected void onPreExecute() {
}
@Override
protected Void doInBackground(Void... voids) {
if (inputFile.endsWith(Config.Docx)||inputFile.endsWith(Config.Doc)||inputFile.endsWith(Config.PPT)||inputFile.endsWith(Config.XLSX)
||inputFile.endsWith(Config.XLS)){
ApiClient defaultClient = Configuration.getDefaultApiClient();
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey(getString(R.string.cloudmersive));
ConvertDocumentApi apiInstance = new ConvertDocumentApi();
File file = new File(inputFile);
try {
if (inputFile.endsWith(Config.Docx)) {
convertedBytes = apiInstance.convertDocumentDocxToPdf(file);
}
else if (inputFile.endsWith(Config.Doc)) {
convertedBytes = apiInstance.convertDocumentPptxToPdf(file);
}
else if (inputFile.endsWith(Config.PPT)) {
convertedBytes = apiInstance.convertDocumentPptxToPdf(file);
}
else if (inputFile.endsWith(Config.XLSX)) {
convertedBytes = apiInstance.convertDocumentXlsxToPdf(file);
}
else if (inputFile.endsWith(Config.XLS)) {
convertedBytes = apiInstance.convertDocumentXlsxToPdf(file);
}
} catch (Exception e) {
Log.d("CloudMersive", "Exception when calling ConvertDocumentApi#convertDocumentDocxToPdf\n");
Log.d("CloudMersive", String.valueOf(e));
e.printStackTrace();
viewerError = false;
}
}
else if (inputFile.endsWith(Config.Text)){
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(new File(inputFile)));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
com.itextpdf.text.Document document = new com.itextpdf.text.Document();
String basePath = null;
File mBaseFolderPath = getExternalFilesDir(null);
if (mBaseFolderPath != null) {
basePath = mBaseFolderPath.getPath().substring(0, mBaseFolderPath.getPath().indexOf("/Android"));
}
File directory = new File(basePath);
dummyFile = new File(directory,"dummy.pdf");
PdfWriter.getInstance(document,new FileOutputStream(dummyFile));
document.open();
Font font = new Font();
font.setSize(16);
document.add(new Phrase(String.valueOf(text),font));
document.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
try {
if (inputFile.endsWith(Config.Docx)||inputFile.endsWith(Config.Doc)||inputFile.endsWith(Config.PPT)||inputFile.endsWith(Config.XLSX)
||inputFile.endsWith(Config.XLS)){
if (Config.checkConnectivity(ViewerActivity.this) && viewerError){
viewerPdfview.fromBytes(convertedBytes)
.enableSwipe(true)
.swipeHorizontal(false)
.enableDoubletap(true)
.defaultPage(0)
.enableAnnotationRendering(true)
.scrollHandle(new DefaultScrollHandle(ViewerActivity.this))
.enableAntialiasing(false)
.pageFitPolicy(FitPolicy.BOTH)
.fitEachPage(true)
.nightMode(false)
.load();
}
else if ((Config.checkConnectivity(ViewerActivity.this)) && !viewerError){
Toast.makeText(ViewerActivity.this,"Your internet connection is poor ",Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(ViewerActivity.this,"Please connect to internet",Toast.LENGTH_LONG).show();
}
}
else if (inputFile.endsWith(Config.Text)){
viewerPdfview.fromFile(dummyFile)
.enableSwipe(true)
.swipeHorizontal(false)
.enableDoubletap(true)
.defaultPage(0)
.enableAnnotationRendering(true)
.scrollHandle(new DefaultScrollHandle(ViewerActivity.this))
.enableAntialiasing(false)
.pageFitPolicy(FitPolicy.BOTH)
.fitEachPage(true)
.nightMode(false)
.load();
}
else if (inputFile.endsWith(Config.PDF)){
viewerPdfview.fromFile(new File(inputFile))
.enableSwipe(true)
.swipeHorizontal(false)
.enableDoubletap(true)
.defaultPage(0)
.enableAnnotationRendering(true)
.scrollHandle(new DefaultScrollHandle(ViewerActivity.this))
.enableAntialiasing(false)
.pageFitPolicy(FitPolicy.BOTH)
.fitEachPage(true)
.nightMode(false)
.load();
}
mspitview.setVisibility(View.GONE);
}
catch (Exception e){
e.printStackTrace();
}
}
}`
MODEL: ONEPLUS A5010 Manufacture: OnePlus SDK: 28 Brand: OnePlus java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.HandlerThread.isAlive()' on a null object reference at com.github.barteksc.pdfviewer.PDFView.loadComplete(PDFView.java:756) at com.github.barteksc.pdfviewer.DecodingAsyncTask.onPostExecute(DecodingAsyncTask.java:80) at com.github.barteksc.pdfviewer.DecodingAsyncTask.onPostExecute(DecodingAsyncTask.java:27) at android.os.AsyncTask.finish(AsyncTask.java:695) at android.os.AsyncTask.access$600(AsyncTask.java:180) at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6898) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)