我在启用proguard时遇到了“getActivity()。getPackageName()”崩溃但工作正常而没有启用

时间:2017-11-27 05:40:41

标签: java android

我正在尝试使用包名称的jsoup在Play商店中获取我的应用程序的版本名称。通过启用prograud在生成构建apk时。获取包名称时会抛出错误。

我正在使用此代码从Play商店中检索版本名称。

@Override
protected String doInBackground(Void... params) {

    String newVersion = null;
    try {
        Log.e("newVersion","newVersion");

        newVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + getActivity().getPackageName() + "&hl=it")
                .timeout(30000)
                .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
                .referrer("http://www.google.com")
                .get()
                .select("div[itemprop=softwareVersion]")
                .first()
                .ownText();

        Log.e("Jsoup.connect","Jsoup.connect");

        return newVersion;
    } catch (Exception e) {
        return newVersion;
    }
}

,我的错误是:

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 Process: com.iroid.android.gk4success_staffnurse, PID: 14673
java.lang.RuntimeException: An error occurred while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:318)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
    at java.lang.Thread.run(Thread.java:762)
Caused by: java.lang.ExceptionInInitializerError
    at org.a.b.i.a(Unknown Source)
    at org.a.b.i$b.<clinit>(Unknown Source)
    at org.a.b.f$a.<init>(Unknown Source)
    at org.a.b.f.<init>(Unknown Source)
    at org.a.c.l.b(Unknown Source)
    at org.a.c.l.a(Unknown Source)
    at org.a.c.b.a(Unknown Source)
    at org.a.c.f.a(Unknown Source)
    at org.a.a.a.a(Unknown Source)
    at org.a.a.b$c.e(Unknown Source)
    at org.a.a.b.a(Unknown Source)
    at com.iroid.android.gk4success_staffnurse.f.a$9.a(Unknown Source)
    at com.iroid.android.gk4success_staffnurse.f.a$9.doInBackground(Unknown Source)
    at android.os.AsyncTask$2.call(AsyncTask.java:304)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
    at java.lang.Thread.run(Thread.java:762) 
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.Reader.read(char[])' on a null object reference
    at java.util.Properties$LineReader.readLine(Properties.java:435)
    at java.util.Properties.load0(Properties.java:354)
    at java.util.Properties.load(Properties.java:342)
    at org.a.b.i.d(Unknown Source)
    at org.a.b.i.<clinit>(Unknown Source)
    at org.a.b.i.a(Unknown Source) 
    at org.a.b.i$b.<clinit>(Unknown Source) 
    at org.a.b.f$a.<init>(Unknown Source) 
    at org.a.b.f.<init>(Unknown Source) 
    at org.a.c.l.b(Unknown Source) 
    at org.a.c.l.a(Unknown Source) 
    at org.a.c.b.a(Unknown Source) 
    at org.a.c.f.a(Unknown Source) 
    at org.a.a.a.a(Unknown Source) 
    at org.a.a.b$c.e(Unknown Source) 
    at org.a.a.b.a(Unknown Source) 
    at com.iroid.android.gk4success_staffnurse.f.a$9.a(Unknown Source) 
    at com.iroid.android.gk4success_staffnurse.f.a$9.doInBackground(Unknown Source) 
    at android.os.AsyncTask$2.call(AsyncTask.java:304) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
    at java.lang.Thread.run(Thread.java:762) 

有谁能告诉我们如何解决这个错误?

2 个答案:

答案 0 :(得分:0)

尝试将newVersion变量声明为空字符串。

String newVersion = "";

答案 1 :(得分:0)

这似乎是与apt-get install相关的Jsoup错误。

Proguard文件中,尝试添加

proguard

-keeppackagenames org.jsoup.nodes