Android-Butterknife: Caused by: java.lang.IllegalStateException: Required view xxx was not found


Android-Butterknife: Caused by: java.lang.IllegalStateException: Required view xxx was not found



Android Studio 3.1,
Gradle 4.1,
Java 1.8,
Android 6.0,
ButterКnife 8.8.1



I try to use ButterKnife on android app. But I have a problem.



in build.gradle:


classpath 'com.android.tools.build:gradle:3.1.2'



in app/build.gradle:


implementation "com.jakewharton:butterknife:8.8.1"
kapt "com.jakewharton:butterknife-compiler:8.8.1"



Here my xml layout: offer_details_pdf.xml


<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include
android:id="@+id/offerDetailsToolBarMainContainer"
layout="@layout/offer_details_top_container"
android:layout_width="0dp"
android:layout_height="56dp"/>

<TextView
android:id="@+id/noItemsTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/no_items"
android:visibility="gone"/>

</android.support.constraint.ConstraintLayout>



In my activity


public class OfferDetailsPdfActivity extends AppCompatActivity implements MyInterface {
@BindView(R.id.offerDetailsToolBarMainContainer)
ConstraintLayout offerDetailsToolBarMainContainer;
@BindView(R.id.noItemsTextView)
TextView noItemsTextView;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
setContentView(R.layout.offer_details_pdf);
ButterKnife.bind(this);
}

// implment method of interface MyInterface
@Override
public void showTopAndBottomContainer() {
offerDetailsToolBarMainContainer.setVisibility(View.VISIBLE);
}

// implment method of interface MyInterface
@Override
public void showNoItems() {
noItemsTextView.setVisibility(View.VISIBLE);
}



Method showTopAndBottomContainer() success work. But method showNoItems() not.
I get error:


showTopAndBottomContainer()


showNoItems()


java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myproject.android.customer.debug/com.myproject.android.customer.ui.OfferDetailsPdfActivity}: java.lang.IllegalStateException: Required view 'noItemsTextView' with ID 2131296554 for field 'noItemsTextView' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: Required view 'noItemsTextView' with ID 2131296554 for field 'noItemsTextView' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.
com.myproject.android.customer.ui.OfferDetailsPdfActivity_ViewBinding.<init>(OfferDetailsPdfActivity_ViewBinding.java:73)
at java.lang.reflect.Constructor.newInstance(Native Method)
at butterknife.ButterKnife.createBinding(ButterKnife.java:199)
at butterknife.ButterKnife.bind(ButterKnife.java:124)



Why it's not working?





Why do you have and @Override above showNoItems() method? Also do you have in gradle: annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
– Yupi
Jun 29 at 8:23


@Override


showNoItems()


annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'





I update my post
– Alexei
Jun 29 at 8:35






@Yupi the @ override most likely comes from the MyInterface interface.
– ZUNJAE
Jun 29 at 8:40





yes, showNoItems() is implement of interface MyInterface
– Alexei
Jun 29 at 8:41





You have to use the annotations on the fields not on any method. And I cannot find R.id.noItemsTextView in the XML. :/
– Abdul Wadood
2 days ago


R.id.noItemsTextView




2 Answers
2



There is no text view matching with id R.id.noItemsTextView in the XML.


R.id.noItemsTextView



You might have forgotten to apply the ButterKnife plugin. Go to your build.gradle file and below apply plugin: 'com.android.library' add this: apply plugin: 'com.jakewharton.butterknife'


apply plugin: 'com.android.library'


apply plugin: 'com.jakewharton.butterknife'





I get error: Plugin with id 'com.jakewharton.butterknife' not found.
– Alexei
Jun 29 at 8:43





Honestly it's best to read the installation guide on GitHub. You also need to include classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1' in your BuildScript. github.com/JakeWharton/butterknife#library-projects
– ZUNJAE
Jun 29 at 8:43


classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'





Unable to find method 'com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;'. Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
– Alexei
Jun 29 at 8:56





Yeah, did you google that error already?
– ZUNJAE
Jun 29 at 9:04





Google not help.
– Alexei
Jun 29 at 9:13






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV