简体   繁体   中英

TextView setText Cannot resolve type

Im using Android Studio, trying set text to Text View but every time i do this

TextView test = (TextView) findViewById(R.id.testView);
test.setText("fds");

on Android Studio i see Cannot resolve symbol 'setText' . Can someone tell me what im doing wrong?

setText() will accept String which you have passed, so there is no issue in that.

One possible reason for this might be you have not written your code inside onCreate() or onCreateView() .

  1. If it is Activity you need to use these lines after setContentView() in onCreate() .
  2. If it is Fragment you need to use these lines after inflating your view in onCreateView() .

Second reason, you might be having one more test variable of different type like String or something else

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