Entry Level Error, Incompatible Types

Now I'm starting to learn Android programming. An example of an old book that I found in it. Here is the problem.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mytextview = findViewById(R.id.textView);
    pluszgomb = findViewById(R.id.button);
    minuszgomb = findViewById(R.id.button2);
    mytextview.setText("A számláló értéke: "+ szamlalo);
    pluszgomb.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
}

Line 5 of Android Studio provides that:

Incompatible type.

Requires: android.widget.View

Found: android.view.View

Where is the problem?

thanks

+4
source share
2 answers

Check your import. If you see

import android.view.View;

You will need to change it to:

import android.widget.View;

Or, if you use android.view.View, you will need to add a cast to android.widget.Viewso

widget.View widgetView = (widget.View) view;
+2
source

check your import, if any:

import android.view.View

then change it to:

import android.widget.View
+1
source

Source: https://habr.com/ru/post/1621646/


All Articles