我在使用 findViewById() 时遇到错误
i'm getting an error while using findViewById()
我想使用方法 (findViewById
),但我收到无法解决的错误。
错误是 "Type Parameter T has incompatible upperbounds: View and RatingBar".
为了解决这个问题,我尝试关闭 activity 并打开另一个,但没有成功。
public class RatingBar extends AppCompatActivity {
RatingBar got , bd;
TextView gottxt , bdtxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rating_bar);
init()
}
private void init(){
got = findViewById(R.id.gotrate);
}
}
您正在使用 RatingBar 作为您的 activity 名称。它是 Android 中的内置 class。更改您的 Activity 的名称并重试
这是问题:` got = findViewById(R.id.gotrate); && 同时更改 Activity 的名称,因为它是保留字
`
会喜欢这个:
public class MyActivity extends AppCompatActivity {
RatingBar got , bd;
TextView gottxt , bdtxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rating_bar);
init()
}
private void init(){
got = (RatingBar)findViewById(R.id.gotrate);
}
将 RatingBar 声明为最终的(例如 Final RatingBar
或 Final TextView
)并查看它是否可以解决问题
我想使用方法 (findViewById
),但我收到无法解决的错误。
错误是 "Type Parameter T has incompatible upperbounds: View and RatingBar".
为了解决这个问题,我尝试关闭 activity 并打开另一个,但没有成功。
public class RatingBar extends AppCompatActivity {
RatingBar got , bd;
TextView gottxt , bdtxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rating_bar);
init()
}
private void init(){
got = findViewById(R.id.gotrate);
}
}
您正在使用 RatingBar 作为您的 activity 名称。它是 Android 中的内置 class。更改您的 Activity 的名称并重试
这是问题:` got = findViewById(R.id.gotrate); && 同时更改 Activity 的名称,因为它是保留字
` 会喜欢这个:
public class MyActivity extends AppCompatActivity {
RatingBar got , bd;
TextView gottxt , bdtxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rating_bar);
init()
}
private void init(){
got = (RatingBar)findViewById(R.id.gotrate);
}
将 RatingBar 声明为最终的(例如 Final RatingBar
或 Final TextView
)并查看它是否可以解决问题