我是Android开发的新手,我遇到了一个奇怪的问题。我试图从AsyncTask拉取并显示日历事件。这在调试模式下工作,但如果我尝试通过apk安装应用程序,应用程序崩溃时会出现此错误:
12-18 08:57:16.768: E/AndroidRuntime(8642): FATAL EXCEPTION: AsyncTask #2
12-18 08:57:16.768: E/AndroidRuntime(8642): java.lang.RuntimeException: An error occured while executing doInBackground()
12-18 08:57:16.768: E/AndroidRuntime(8642): at android.os.AsyncTask$3.done(AsyncTask.java:299)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-18 08:57:16.768: E/AndroidRuntime(8642): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.lang.Thread.run(Thread.java:856)
12-18 08:57:16.768: E/AndroidRuntime(8642): Caused by: java.lang.IllegalArgumentException: unable to create new instance of class com.a.b.b.a.a.b because it has no accessible default constructor
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.e.aa.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.e.aa.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.e.i.b(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source) 12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.f.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.f.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.c.t.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.b.d.c.d(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.promevo.bookit.a.f(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.promevo.bookit.a.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.promevo.bookit.f.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.promevo.bookit.f.doInBackground(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-18 08:57:16.768: E/AndroidRuntime(8642): ... 5 more
12-18 08:57:16.768: E/AndroidRuntime(8642): Caused by: java.lang.InstantiationException: can't instantiate class com.a.b.b.a.a.b; no empty constructor
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.lang.Class.newInstanceImpl(Native Method)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.lang.Class.newInstance(Class.java:1319)
我正在打电话:
Events feed = client.events().list(CalendarSampleActivity.getCalId()).setTimeMin(startPass)
.setTimeMax(endPass).setSingleEvents(true).execute();
有人有什么想法吗?提前谢谢。
好的,经过一些故障排除后,使用Proguard时似乎出现了问题。如果我从project.properties文件中删除此行,我的应用程序现在可以运行:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt:proguard-google-api-client.txt
任何人都知道为什么会产生影响?
答案 0 :(得分:2)
在此处阅读Proguard和Android:http://developer.android.com/tools/help/proguard.html
由于您获得了“无法访问的默认构造函数”异常,因此Proguard很可能已从包中删除此构造函数,因为它无法找到此构造函数的用户(Proguard会从包中删除不可访问或未使用的代码它更小)。你必须告诉Proguard在包装中保留某些代码,即使它没有明显使用。
另一种方法是禁用Proguard以进行发布版本。