Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android-黄油刀8.8.1 NullPointerException_Android_Android Layout_Butterknife - Fatal编程技术网

android-黄油刀8.8.1 NullPointerException

android-黄油刀8.8.1 NullPointerException,android,android-layout,butterknife,Android,Android Layout,Butterknife,我使用的是butterknife:8.8.1,就像前面提到的那样 我的项目等级如下 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1' ... } } apply plugin: 'com.jakewharton.butterk

我使用的是butterknife:8.8.1,就像前面提到的那样

我的项目等级如下

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
        ...

    }
}
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
dependencies {
    ...    
    compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.details);
    ButterKnife.bind(this);
    ButterKnife.setDebug(true);
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/device_info_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/sensor_settings_background">

    ....
   <RelativeLayout
        android:id="@+id/container_buttons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:background="@color/settings_background">

        <Button
            android:id="@+id/connect_button"
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:layout_alignParentLeft="true"
            android:background="@drawable/selector"
            android:text="@string/connect"
            android:textColor="@color/red"
            android:textStyle="italic" />

        <Button
            android:id="@+id/register_button"
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="4dp"
            android:text="@string/register"
            android:visibility="gone" />

        <Button
            android:id="@+id/unregister_button"
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:layout_alignParentRight="true"
            android:background="@drawable/selector"
            android:text="@string/unregister"
            android:textColor="@color/red"
            android:textStyle="italic"
            android:visibility="gone"
            tools:visibility="visible" />
    </RelativeLayout>
</RelativeLayout>
模块级渐变如下所示

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
        ...

    }
}
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
dependencies {
    ...    
    compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.details);
    ButterKnife.bind(this);
    ButterKnife.setDebug(true);
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/device_info_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/sensor_settings_background">

    ....
   <RelativeLayout
        android:id="@+id/container_buttons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:background="@color/settings_background">

        <Button
            android:id="@+id/connect_button"
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:layout_alignParentLeft="true"
            android:background="@drawable/selector"
            android:text="@string/connect"
            android:textColor="@color/red"
            android:textStyle="italic" />

        <Button
            android:id="@+id/register_button"
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="4dp"
            android:text="@string/register"
            android:visibility="gone" />

        <Button
            android:id="@+id/unregister_button"
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:layout_alignParentRight="true"
            android:background="@drawable/selector"
            android:text="@string/unregister"
            android:textColor="@color/red"
            android:textStyle="italic"
            android:visibility="gone"
            tools:visibility="visible" />
    </RelativeLayout>
</RelativeLayout>
活动文件如下所示

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
        ...

    }
}
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
dependencies {
    ...    
    compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.details);
    ButterKnife.bind(this);
    ButterKnife.setDebug(true);
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/device_info_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/sensor_settings_background">

    ....
   <RelativeLayout
        android:id="@+id/container_buttons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:background="@color/settings_background">

        <Button
            android:id="@+id/connect_button"
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:layout_alignParentLeft="true"
            android:background="@drawable/selector"
            android:text="@string/connect"
            android:textColor="@color/red"
            android:textStyle="italic" />

        <Button
            android:id="@+id/register_button"
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="4dp"
            android:text="@string/register"
            android:visibility="gone" />

        <Button
            android:id="@+id/unregister_button"
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:layout_alignParentRight="true"
            android:background="@drawable/selector"
            android:text="@string/unregister"
            android:textColor="@color/red"
            android:textStyle="italic"
            android:visibility="gone"
            tools:visibility="visible" />
    </RelativeLayout>
</RelativeLayout>
xml文件如下所示

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
        ...

    }
}
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
dependencies {
    ...    
    compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.details);
    ButterKnife.bind(this);
    ButterKnife.setDebug(true);
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/device_info_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/sensor_settings_background">

    ....
   <RelativeLayout
        android:id="@+id/container_buttons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:background="@color/settings_background">

        <Button
            android:id="@+id/connect_button"
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:layout_alignParentLeft="true"
            android:background="@drawable/selector"
            android:text="@string/connect"
            android:textColor="@color/red"
            android:textStyle="italic" />

        <Button
            android:id="@+id/register_button"
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="4dp"
            android:text="@string/register"
            android:visibility="gone" />

        <Button
            android:id="@+id/unregister_button"
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:layout_alignParentRight="true"
            android:background="@drawable/selector"
            android:text="@string/unregister"
            android:textColor="@color/red"
            android:textStyle="italic"
            android:visibility="gone"
            tools:visibility="visible" />
    </RelativeLayout>
</RelativeLayout>

有人能帮我理解我做错了什么吗。

我也遇到过同样的问题。 将按钮更改为AppCompatButton,问题已解决

<android.support.v7.widget.AppCompatButton
    android:id="@+id/connect_button"
    android:layout_width="wrap_content"
    android:layout_height="36dp"
    android:layout_alignParentLeft="true"
    android:background="@drawable/selector"
    android:text="@string/connect"
    android:textColor="@color/red"
    android:textStyle="italic" />

我确实遇到过同样的问题。 将按钮更改为AppCompatButton,问题已解决

<android.support.v7.widget.AppCompatButton
    android:id="@+id/connect_button"
    android:layout_width="wrap_content"
    android:layout_height="36dp"
    android:layout_alignParentLeft="true"
    android:background="@drawable/selector"
    android:text="@string/connect"
    android:textColor="@color/red"
    android:textStyle="italic" />


R2?为什么不是R.id什么的?在最新的lib 8.8.1中,请阅读这一行*现在确保在所有黄油刀注释中使用R2而不是R。此外,现在R2用于库项目时,它将不允许使用R.id。如果您有一个库项目:请将您的xml布局添加到问题中。否则,使用R.id.xxIs是您的项目库还是应用程序?它用于库项目,不允许使用R.id.xxR2?为什么不是R.id什么的?在最新的lib 8.8.1中,请阅读这一行*现在确保在所有黄油刀注释中使用R2而不是R。此外,现在R2用于库项目时,它将不允许使用R.id。如果您有一个库项目:请将您的xml布局添加到问题中。否则,使用R.id.xxi是您的项目库还是应用程序?它用于库项目,不允许使用R.id.xx