1

XML part:

 <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="88dp"
        android:text="4"
        android:textSize="90sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

METHOD :

public void tapButton(View view) {

        String str = " Hello";
        textView.text = str;
    }

I saw a few answers but they didnt help out...i need help!!

Yousaf
  • 27,861
  • 6
  • 44
  • 69
AlkalineD
  • 13
  • 7

2 Answers2

0

Did you import TextView? If not, add it like this:

import android.widget.TextView;
Dennis Kozevnikoff
  • 2,078
  • 3
  • 19
  • 29
  • i did but it import word gets black...so i guess its a problem with it and textview in import also says cannot resolve symbol – AlkalineD Jul 03 '20 at 17:07
  • Importing a type doesn't mean that it will be auto initialized. Make your grounds clear before giving a lecture on how jvm optimizes stuff. Owning a youtube channel doesn't mean you know stuff. – Concurrent Bhai Jul 24 '20 at 16:59
0

You have to declare and initialize the variable textView:

    setContentView(R.layout.activity_main);

    TextView textView = findViewById(R.id.textView);
    textView.setText(....);
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841