hdodenhof / CircleImageView

A circular ImageView for Android
Apache License 2.0
14.55k stars 3.12k forks source link

Cannot call CircleImage View by id to use it. #265

Closed MohamedMedhat2018 closed 6 years ago

MohamedMedhat2018 commented 6 years ago

I have an Error it's occur when i try to call the image by its ID -XML code : <de.hdodenhof.circleimageview.CircleImageView android:id="@+id/setup_image" -Java file `import de.hdodenhof.circleimageview.CircleImageView;

public class SetupActivity extends AppCompatActivity {

private CircleImageView setupImage;

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_setup);

    //the error happen when i write this lone
    setupImage = findViewById(R.id.setup_image);`

----------Error: E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.mohamed.photo_blog, PID: 8120 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mohamed.photo_blog/com.example.mohamed.photo_blog.SetupActivity}: java.lang.ClassCastException: android.support.constraint.ConstraintLayout cannot be cast to de.hdodenhof.circleimageview.CircleImageView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2799) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864) at android.app.ActivityThread.access$900(ActivityThread.java:181) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6126) 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:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) Caused by: java.lang.ClassCastException: android.support.constraint.ConstraintLayout cannot be cast to de.hdodenhof.circleimageview.CircleImageView at com.example.mohamed.photo_blog.SetupActivity.onCreate(SetupActivity.java:33)

Appreciate the help.

hdodenhof commented 6 years ago

The exception says: [..]ConstraintLayout cannot be cast to [..]CircleImageView so it seems findViewById(R.id.setup_image) returns a ConstraintLayout - that's not an issue with this library. Please double-check your IDs and maybe clean the project.

MohamedMedhat2018 commented 6 years ago

what do you mean by check your IDs and maybe clean the project?

hdodenhof commented 6 years ago

Make sure that (a) @+id/setup_image is only used once, at the correct place and (b) you are inflating the correct layout. Use "Clean Project" from the "Build" menu in Android Studio.

MohamedMedhat2018 commented 6 years ago

thank you so much you save the rest of my day Have a nice day bro