简体   繁体   中英

android studio casting warning

I mistakenly disable this feature but I don't know how to enable again. The feature is that warns me when I cast an object to another class. For example:

ImageView scanner;
TextView errorMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
    errorMessage = (TextView) findViewById(R.id.errorMessage);
    scanner = (TextView) findViewById(R.id.scanner); // studio warns me when I do this cast, but I mistakenly close this feature
}

Thanks

EDIT

this is the exact solution:

这是确切的解决方案

You decalred scanner as imageview on top

ImageView scanner;

and you are tying to cast it to textview in oncreate, that is not possible.

Change

scanner = (TextView) findViewById(R.id.scanner);

to

scanner = (ImageView) findViewById(R.id.scanner);

You can try the following trick:

Step 1: Find the inspector icon (a human with a cap) at the bottom right corner of your Android Studio.

Step 2: Click on that and you can find a seek bar. It will help you to enable/disable or even you can configure it according to your need.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM