Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.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中的ButterKnife问题_Android_Butterknife_Android Mvp - Fatal编程技术网

android中的ButterKnife问题

android中的ButterKnife问题,android,butterknife,android-mvp,Android,Butterknife,Android Mvp,我正在将butterknife与改装一起使用。当我使用网络调用连续加载片段时,我的片段在视图上的空指针下崩溃。我已经在片段中实现了解除绑定 使用findviewbyid执行相同操作时,我没有遇到错误。Iam使用MVP Unbinder unbinder; @BindView(R.id.swipe_refresh_layout) SwipeRefreshLayout swipeRefreshLayout; @BindView(R.id.recycler_view_shop) RecyclerVi

我正在将
butterknife
改装一起使用。当我使用网络调用连续加载片段时,我的片段在视图上的空指针下崩溃。我已经在片段中实现了解除绑定

使用
findviewbyid
执行相同操作时,我没有遇到错误。Iam使用MVP

Unbinder unbinder;
@BindView(R.id.swipe_refresh_layout)
SwipeRefreshLayout swipeRefreshLayout;

@BindView(R.id.recycler_view_shop)
RecyclerView recyclerView;

@BindView(R.id.ll_content)
LinearLayout layoutContent;

@BindView(R.id.ll_no_data)
LinearLayout layoutNoData;

@BindView(R.id.tv_category_heading)
TextView categoryHeading;

private HomeActivity activity;
private ProgressDialog progressDialog;
DrListFragmentPresenter presenter;


public DrListFragment() {
    // Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_dr, container, false);
    // bind view using butter knife
    unbinder = ButterKnife.bind(this, rootView);

    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.addItemDecoration(new DividerItemDecoration(getFragment().getActivity(),DividerItemDecoration.VERTICAL));

    activity = (HomeActivity) getActivity();

    presenter = new DrListFragmentPresenterImpl(this);
    return rootView;
}

@Override
public Fragment getFragment() {
    return this;
}


@Override
public void setCategoriesDetailsAdapter(CategoryWiseItemListingAdapter adapter) {
    recyclerView.setAdapter(adapter);
}





@Override
public void onDestroyView() {
    super.onDestroyView();

    // unbind the view to free some memory
    unbinder.unbind();
}    

}

检查
项目梯度

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
    // add this in your code
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'  
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'  // add this 

...
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.jakewharton:butterknife:8.6.0'
    // add this 
    apt 'com.jakewharton:butterknife-compiler:8.6.0
}
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'
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
    }
}
检查
appgradle

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
    // add this in your code
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'  
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'  // add this 

...
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.jakewharton:butterknife:8.6.0'
    // add this 
    apt 'com.jakewharton:butterknife-compiler:8.6.0
}
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'
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
    }
}
在版本
8.8.1
您可以在
app gradle

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
    // add this in your code
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'  
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'  // add this 

...
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.jakewharton:butterknife:8.6.0'
    // add this 
    apt 'com.jakewharton:butterknife-compiler:8.6.0
}
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'
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
    }
}
并将其添加到
项目gradle

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
    // add this in your code
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'  
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'  // add this 

...
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.jakewharton:butterknife:8.6.0'
    // add this 
    apt 'com.jakewharton:butterknife-compiler:8.6.0
}
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'
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
    }
}
你可以查一下


检查
项目梯度

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
    // add this in your code
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'  
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'  // add this 

...
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.jakewharton:butterknife:8.6.0'
    // add this 
    apt 'com.jakewharton:butterknife-compiler:8.6.0
}
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'
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
    }
}
检查
appgradle

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
    // add this in your code
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'  
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'  // add this 

...
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.jakewharton:butterknife:8.6.0'
    // add this 
    apt 'com.jakewharton:butterknife-compiler:8.6.0
}
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'
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
    }
}
在版本
8.8.1
您可以在
app gradle

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
    // add this in your code
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'  
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'  // add this 

...
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.jakewharton:butterknife:8.6.0'
    // add this 
    apt 'com.jakewharton:butterknife-compiler:8.6.0
}
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'
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
    }
}
并将其添加到
项目gradle

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
    // add this in your code
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'  
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'  // add this 

...
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.jakewharton:butterknife:8.6.0'
    // add this 
    apt 'com.jakewharton:butterknife-compiler:8.6.0
}
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'
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
    }
}
你可以查一下


我对以下场景也有同样的问题:

  • 开放片段A
  • 打开片段B(快速,在输入数据之前 片段A(出现)
  • 重新打开片段A
  • 当第一次打开片段A时,Regent调用API,在调用完成之前,移动到片段B,然后片段A将被调用
    onDestroyView
    。在这种方法中,butterknife是
    未绑定的
    。当返回到片段A时,将调用来自API的响应过程,现在该组件为null,因为它已取消绑定

    解决方案:使用
    call.cancel()


    我对以下场景也有同样的问题:

  • 开放片段A
  • 打开片段B(快速,在输入数据之前 片段A(出现)
  • 重新打开片段A
  • 当第一次打开片段A时,Regent调用API,在调用完成之前,移动到片段B,然后片段A将被调用
    onDestroyView
    。在这种方法中,butterknife是
    未绑定的
    。当返回到片段A时,将调用来自API的响应过程,现在该组件为null,因为它已取消绑定

    解决方案:使用
    call.cancel()


    你能把毕业证书寄出去吗?和错误日志给出适配器的完整代码。在该片段中添加错误日志i am get null pointer exception of basic vie。现在我在滑动刷新布局上得到空指针。如果我和findviewbyId绑定它的工作技巧,你能发布你的毕业证书吗?和错误日志给出适配器的完整代码。在该片段中添加错误日志i am get null pointer exception of basic vie。现在我在滑动刷新布局上得到空指针。如果我将vie与findviewbyId绑定,则无需将apt“com…”添加到gradle文件中。检查。谢谢你的回答。但在我的代码中,我添加了这个,效果很好。在新版本中,它将添加另一个。是的,可能你使用的是butterknife的旧版本。没有必要将apt“com…”添加到gradle文件中。检查。谢谢你的回答。但在我的代码中,我添加了这个,效果很好。在新版本中,它将添加另一个。是的,可能你使用的是旧版本的butterknife。