Faza
Faza

Reputation: 1

Butterknife.bind layout issue

I can't understand whyButterKnife.bind(this)gives an error? To the point, here is my code: althoung this is the second activity. But in the first activity i don't get any problem. The code is:-

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

init();
getFriendList();
}

at the ButterKnife.bind(this); it says

Caused by: java.lang.IllegalStateException: Required view 'progress_bar' with ID 2131230925 for field 'progressBar' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.
at butterknife.internal.Utils.findRequiredView(Utils.java:92)
at butterknife.internal.Utils.findRequiredViewAsType(Utils.java:104)
at com.example.first.cvpunyanongs.All_Area_ViewBinding.<init>(All_Area_ViewBinding.java:26)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at butterknife.ButterKnife.createBinding(ButterKnife.java:199)
at butterknife.ButterKnife.bind(ButterKnife.java:124)
at com.example.first.cvpunyanongs.All_Area.onCreate(All_Area.java:56)
at android.app.Activity.performCreate(Activity.java:6177)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2541)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685) 
at android.app.ActivityThread.access$900(ActivityThread.java:188) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1530) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:210) 
at android.app.ActivityThread.main(ActivityThread.java:5839) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1113) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:879) 

any help would be great!

Upvotes: 0

Views: 320

Answers (1)

Anurag Chutani
Anurag Chutani

Reputation: 595

ButterKnife.bind(this); 

should be after

setContentView(R.layout.activity_main);

Try like this:

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);

   setContentView(R.layout.activity_main);
   ButterKnife.bind(this);

   init();
   getFriendList();
}

Upvotes: 1

Related Questions