使用PDF Viewer Lib时出现空指针异常

哈吉·阿里

使用AndroidPdfViewer库时遇到以下错误。这是我遇到的错误:

FATAL EXCEPTION: main
                                                                     Process: app.com.application, PID: 16559
                                                                     java.lang.NullPointerException: Attempt to invoke virtual method 'com.github.barteksc.pdfviewer.PDFView$Configurator com.github.barteksc.pdfviewer.PDFView.fromStream(java.io.InputStream)' on a null object reference
                                                                         at app.com.application.activity.Main2Activity$RetrievePDFStream.onPostExecute(Main2Activity.java:65)
                                                                         at app.com.application.activity.Main2Activity$RetrievePDFStream.onPostExecute(Main2Activity.java:38)

我的代码:

public class Main2Activity extends Activity {

String URL_PDF = "http://192.168.1.103/android_login_api/PDF/1G.pdf";
    PDFView pdfView;

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

    // view pdf from url
    new RetrievePDFStream().execute(URL_PDF);

}

 private class RetrievePDFStream extends AsyncTask <String, Void, InputStream>{
     @Override
     protected InputStream doInBackground(String... strings) {
         InputStream inputStream = null;
         URL url = null;
         try {
             url = new URL(strings[0]);
         } catch (MalformedURLException e) {
             e.printStackTrace();
         }

         try {
             HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
             if (httpURLConnection.getResponseCode()==200){

                 inputStream = new BufferedInputStream(httpURLConnection.getInputStream());
             }
         } catch (IOException e) {
             return null;
         }

        return inputStream;
     }


     @Override
     protected void onPostExecute(InputStream inputStream) {
         pdfView.fromStream(inputStream).load();
     }
     }

}

请指导我解决问题,谢谢。我也有另一个问题:是否可以使用此方法Volley代替AsyncTask

加布里埃尔·玛丽奥蒂(Gabriele Mariotti)

发生是因为pdfViewnull。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用'com.github.barteksc:android-pdf-viewer:2.8.2'库打开pdf时出现黑屏

使用空引用访问数组时出现空指针异常

在Java中使用泛型时出现空指针异常

使用 AutocompleteTextView 和 BaseAdapter 时出现空指针异常

使用Java Compiler API时出现空指针异常

使用Bundle传递数据时出现空指针异常

在黄瓜中使用 pojo 类时出现空指针异常

使用LayoutInflator()时是否出现空指针异常?

使用@Autowired注解注入Bean时出现空指针异常

使用JDBC查询执行executeUpdate时出现空指针异常

尝试使用 riemann 写入文件时出现空指针异常

Flutter:当我使用full_pdf_viewer时,我的应用程序停止了

使用ng2-pdf-viewer时ng-serve错误

在端口5938被阻止时使用Team Viewer?

Android PDF Viewer空对象引用错误

PDF Viewer库的路径

在 spring security dofilter 身份验证方法中使用 @Autowired 注释时出现空指针异常

使用BIMserver Java客户端检索类的所有实例时,出现空指针异常

使用共享首选项在onCreate中检索textView时出现空指针异常

在JENA virtuoso中的SPARQL查询中使用BIND时出现空指针异常错误

使用Admob中介显示Vungle广告时,出现空指针异常

在 Fragment 中使用适配器时出现空指针异常

在 Android Studio 中使用 ListView 时出现运行时错误(空指针异常)

使用HttpSession时获取空指针异常

使用Mockito时面临空指针异常

使用imageView时,空指针异常

使用ngx-extended-pdf-viewer访问多个pdf

禁用HTML PDF Viewer对象

sessionFactory bean:使用setter注入时出现空指针异常