-2

Hi i am new to android prgramming, so i wrote this simple code just to try it, it works just fine in android studio emulator but when i use build apk and install the app manually on my phone it crashes when i tap on the button i tried it in few phones with android 7, android 5 and andorid 4.4 all gave me the same result. I use android studio 3.0 and the minimum api i used android 4.0.3 for this project. what could be the problem.

package com.example.adem.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    void tst(View v) {
        TextView t= this.findViewById(R.id.temo);
        t.setText("he");
    }
}

XML file:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.adem.myapplication.MainActivity">

<TextView
    android:id="@+id/temo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="168dp"
    android:layout_marginTop="164dp"
    android:text="Button"
    android:onClick="tst"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
dark.semiQ
  • 111
  • 1
  • 7

1 Answers1

0

thank you guys for replying i found the problem that i was not setting function tst to public this the solution

public void tst(View view){
    TextView t= this.findViewById(R.id.temo);
    t.setText("he");
}
dark.semiQ
  • 111
  • 1
  • 7