JakeWharton / butterknife

Bind Android views and callbacks to fields and methods.
http://jakewharton.github.io/butterknife/
Apache License 2.0
25.55k stars 4.61k forks source link

@BindView with same ID compile error without any error message #593

Closed miszmaniac closed 8 years ago

miszmaniac commented 8 years ago

Hi,

Bug is in version 8.0.1

I've found out that making faulty holder like this one (with same 2 IDs), will give you compile error without any message of what happened.

public static class Holder1 extends RecyclerView.ViewHolder {

        @BindView(R.id.item)
        public View view1;

        @BindView(R.id.item)
        public View view2;

        public Holder1(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
SimonVT commented 8 years ago

I get error: Attempt to use @BindView for an already bound ID 2131558672 on 'view1' along with class, line number and everything.

JakeWharton commented 8 years ago

And there's a test for that message being displayed: https://github.com/JakeWharton/butterknife/blob/31c1a959252592696d6aa16186c1d69493ca8b87/butterknife-compiler/src/test/java/butterknife/BindViewTest.java#L828

miszmaniac commented 8 years ago

I'm sorry I'm unable to reproduce this in clean new project.

I thought it had something to do with conflict with AndroidAnnotations library, but message do appear with this library present.

I'm still able to reproduce this without trouble in my regular project, just by making copy of any binded field inside any holder. I've check if this has something to do with "@Ebean" annotation on Adapter, but it doesn't, also checked if different packages could cause this, but also nothing. I don't know how but maybe problem lies somewhere else.

If I ever reproduce this I'll write again.

mozi22 commented 8 years ago

@SimonVT did you find the solution for the problem ?

SimonVT commented 8 years ago

There's no issue, the error I posted is the intended behavior. Don't bind the same View multiple times.

On Mon, Aug 1, 2016, 12:21 Muazzam Ali notifications@github.com wrote:

@SimonVT https://github.com/SimonVT did you find the solution for the problem ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/JakeWharton/butterknife/issues/593#issuecomment-236543980, or mute the thread https://github.com/notifications/unsubscribe-auth/AAhh9VzspN6j4LVBIrtt53jz9s4JjrA5ks5qbcingaJpZM4ImYb- .

j796160836 commented 6 years ago

My case is bind a view with wrong view type, it will cause the similar error. For example

Your activity_main.xml maybe

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</RelativeLayout>

Your MainActivity.java maybe

public static class MainActivity extends AppCompatActivity {

    @BindView(R.id.main_content)
    LinearLayout mainContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ButterKnife.bind(this)
    }
}
KgotsoK commented 4 years ago

I have experienced a variance of this issue. Reported here: https://issuetracker.google.com/issues/143550689