Search code examples
androidfindviewbyid

i'm getting an error while using findViewById()


i want to use the method (findViewById) but i get an error which i cant solve. the error is "Type Parameter T has incompatible upperbounds: View and RatingBar".

For fixing this i tried closing the activity and opening another one but it didn't work.

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);
    }
}

Solution

  • Here is Problem : ` got = findViewById(R.id.gotrate); && Also Change Name of Activity becauase it is reserved Word

    ` it will like this :

    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); 
    }