-1

In my application I am trying to click on the text view and redirect it to another location. But after opening the application, when I click on the text view, my application closes. Where am I making the mistake? Can you help me?

MainActivity;

txt_kayitsayfasinagit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            startActivity(new Intent(MainActivity.this,KaydolActivity.class));

        }
    });

TextView;

<TextView
    android:id="@+id/txt_kayitsayfasinagit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hesabin_yok_mu_kaydol"
    android:textColor="#B2B2B2"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/btn_giris"
    app:layout_constraintVertical_bias="0.10" />

Manifest;

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.Picker">
    <activity android:name=".KaydolActivity" />
    <activity android:name=".AnaSayfaActivity" />

    <meta-data
        android:name="com.google.android.actions"
        android:resource="@xml/background_splash" />
    <meta-data
        android:name="preloaded_fonts"
        android:resource="@array/preloaded_fonts" />

    <activity android:name=".SplashActivity" />
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Logcat;

enter image description here

enter image description here

enter image description here

Takker
  • 11
  • 2
  • 1
    Use Logcat to examine the stack trace associated with your crash: https://stackoverflow.com/q/23353173/115145 – CommonsWare Nov 21 '20 at 13:45
  • 1
    It closes because there's probably an exception occurring somewhere. It would help if you posted your logcat as well – QBrute Nov 21 '20 at 13:49
  • add full mainactivity code to the question – Wahdat Jan Nov 21 '20 at 13:49
  • first you need to understand whether the app is crashing or not. then, Where is it crashing? in the main activity or the KaydolActivity activity. and then share the code to the activity that crashes. – MehranB Nov 21 '20 at 15:42
  • As you said, I installed logcats, you can look at the photos. – Takker Nov 21 '20 at 19:33
  • The problem is that you Can not cast a MaterialTextView to an EditText, I guess you wanted to cast it to TextView, so check if this is the problem. – malekiamir Nov 21 '20 at 19:44
  • I have no idea how to fix this problem – Takker Nov 21 '20 at 19:59

2 Answers2

0

Initialize the EditText first, like this:

EditText text;

text = findViewById(R.id.txt_kayitsayfasinagit);

then add listener for the text, like this:

text.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            startActivity(new Intent(MainActivity.this,KaydolActivity.class));

        }
    });
  • I did the way you said, but I get an error, I added it as a photo. You can check the error I received above. The error it gives is fixed when I do "EditText" from "activty_main.xlm" to "TextView", this time when I click on it the text is written and it closes again. – Takker Nov 22 '20 at 13:07
  • Brother make sure that you are casting EditText both in activity and XML in same version. either use Material EditText on both case. Or use Androidx Compat EditText – Emon Hossain Munna Nov 22 '20 at 14:52
  • I've checked everything but unfortunately can't fix the error. There is a "sign up" text on my login screen. I'm trying to be directed to the "sign up" page by clicking it, but I still haven't succeeded. – Takker Nov 22 '20 at 15:02
-2

I'm not seeing any mistakes in your code. Is the MainActivity code properly inside the onCreate() or onStart() method? A good tip is to look at the logcat to see the error message.