当前位置: 安卓之星 -> 安卓开发 -> Butterknife8.1.0 提示NullPointerException空指针

Butterknife8.1.0 提示NullPointerException空指针

作者:网络 发表于: 2016-08-26 点击: 539 次

Butterknife 8.0以后的版本在引入到项目中有变动,按之前的引入方式之后, 会报 空指针!
正确的引入方法是:(在官方的文件上有说明的,记录是为了方便下次引入,直接复制到项目)
在项目的.gradle文件中加入:

<code class=”hljs scala”><span style=”font-size: 14px;”><font face=”微软雅黑”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>classpath </span><span class=”hljs-symbol”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>’com</span></span><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>.neenbedankt.gradle.plugins:android-apt:</span><span class=”hljs-number”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>1.8</span></span><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>'</span></font></span></code>

<code class=”hljs scala”><span style=”font-size: 14px;”><br style=”font-size: 1.2rem;”></span></code>

<code class=”hljs scala”><span style=”font-size: 14px;”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>在引入依赖库的.gradle文件加入</span></span></code>

<span style=”font-size: 14px; font-family: Helvetica, ‘Hiragino Sans GB’, 微软雅黑, ‘Microsoft YaHei UI’, SimSun, SimHei, arial, sans-serif; line-height: 1.6;”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>apply plugin: </span></span><span class=”hljs-symbol” style=”font-size: 14px; font-family: Helvetica, ‘Hiragino Sans GB’, 微软雅黑, ‘Microsoft YaHei UI’, SimSun, SimHei, arial, sans-serif; line-height: 1.6;”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>’com</span></span><span style=”font-size: 14px; font-family: Helvetica, ‘Hiragino Sans GB’, 微软雅黑, ‘Microsoft YaHei UI’, SimSun, SimHei, arial, sans-serif; line-height: 1.6;”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>.neenbedankt.android-apt</span></span><span class=”hljs-symbol” style=”font-size: 14px; font-family: Helvetica, ‘Hiragino Sans GB’, 微软雅黑, ‘Microsoft YaHei UI’, SimSun, SimHei, arial, sans-serif; line-height: 1.6;”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>'</span></span>

<span class=”hljs-symbol” style=”font-size: 14px; line-height: 1.6;”><pre class=”brush:java;toolbar: true; auto-links: false;”><code class=”hljs scala”><font face=”微软雅黑”><span class=”hljs-symbol”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>dependencies</span></span><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”> {</span><span style=”font-size: 1.2rem;”><br style=”font-size: 1.2rem;”></span><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>  compile </span><span class=”hljs-symbol”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>’com</span></span><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>.jakewharton:butterknife:</span><span class=”hljs-number”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>8.1</span></span><span class=”hljs-number”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>.0</span></span><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>'</span><span style=”font-size: 1.2rem;”><br style=”font-size: 1.2rem;”></span><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>  apt </span><span class=”hljs-symbol”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>’com</span></span><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>.jakewharton:butterknife-compiler:</span><span class=”hljs-number”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>8.1</span></span><span class=”hljs-number”><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>.0</span></span><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>'</span><span style=”font-size: 1.2rem;”><br style=”font-size: 1.2rem;”></span><span data-wiz-span=”data-wiz-span” style=”font-size: 1.2rem;”>}</span></font></code></pre><pre class=”brush:java;toolbar: true; auto-links: false;” style=”font-family: Helvetica, ‘Hiragino Sans GB’, 微软雅黑, ‘Microsoft YaHei UI’, SimSun, SimHei, arial, sans-serif;”><br></pre></span>

相关文章

相关文章

赶快留言冒泡

  • 评论 (0)
  • 引用通告 (0)
目前还没有任何评论.
目前还没有任何Trackbacks和Pingbacks.
吐个泡浮上去.