在我的gradle中设置java.lang.RuntimeException: Unable to start activity ComponentInfo{de.ae.formulaecalendar/de.ae.formulaecalendar.view.calendar.CalendarActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2444)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2504)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1367)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
at de.ae.formulaecalendar.view.calendar.CalendarActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2397)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2504)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1367)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
时,我在启动应用时会收到 NullPointerException :
######### KEEP ANDROID SUPPORT V7 AND DESIGN
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
在阅读StackOverflow时,我找到了 proguard-rules.pro 文件的一些设置:
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}
并没有真正解决这个问题(但是之前的NullPointerException)。
最后我的gradle的重要部分:
minifyEnabled
当我解除{{1}}时,其工作正常。
感谢您的帮助!
答案 0 :(得分:2)
大多数时候因为android libs错误,试试这个
-keep interface android.support.** { *; }
-keep class android.support.** { *; }
答案 1 :(得分:1)
我们的想法是保留您项目中包含的库提供的文件。我正在分享我的proguard-rules.pro
之一,这可能有助于您理解。
-keep class com.google.** { *; }
-keep class com.github.** { *; }
-keep class org.apache.** { *; }
-keep class com.android.** { *; }
-keep class junit.** { *; }
-keep class android.support.v7.widget.SearchView { *; }
-keep class com.myproject.model.** { *; }
希望有所帮助!
答案 2 :(得分:1)
当序列化对象并且@SerializedName("param")
(或类似)没有注释字段时,可能会发生这种情况,因此无法找到。
对于调试,它还有助于暂时设置-keepnames class **
,以便不对类名进行模糊处理。
答案 3 :(得分:0)
我解决了这个问题:
在Android Studio中运行Clean Project
后,我收到了一个名为 resource-release-stripped.ap _ 的文件无法找到的错误。一些通过Google搜索显示我需要在gradle文件中禁用shrinkResources
,因为它与Jack不兼容。
答案 4 :(得分:0)
对我来说,添加行(您可能在放置POJO文件的包中使用其他名称):
class PaperCrawler(Spider):
name = "PaperCrawler"
allowed_domains = ["proceedings.mlr.press"]
start_urls = ["http://proceedings.mlr.press/v97/", ]
def parse(self, response):
papers = Selector(response).xpath('//*[@id="content"]/div/div[@class="paper"]')
for paper in papers:
item = PapercrawlerItem()
item['title'] = paper.xpath('p[1]/text()').extract()[0]
item['pdf'] = paper.xpath('p[3]/a[2]/@href').extract()[0]
_sup_data = paper.xpath('p[3]/a[3]/@href').extract()
item['sup'] = '' if len(_sup_data) == 0 else (_sup_data[0] if 'github' not in _sup_data[0] else '')
yield item
对-keep class [mypackagename].model.** { *; }
-keep class [mypackagename].datamodel.** { *; }
的使用效果很好,然后选择了
proguard.rules
在android
{
...
buildTypes {
release {
minifyEnabled true
shrinkResources true
}
}
}
中设置(模块:应用)