Aniket Jadhav
Aniket Jadhav

Reputation: 578

My app crashes while clicking on a TextView

Whenever I run my application on my phone, it works fine and opens Correctly but as soon as I clicked the TextView for typing some text in that, The Application gets crashed. I got a similar post like this on the forum but It couldn't help me out. Don't know at all What actually happened. New in Android Platform. (please, Ask me if need something regarding Question)

MainActivity.java

       import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    public void ButtonClicked(View view){

        EditText EnteredAmount = (EditText) findViewById(R.id.EnteredAmount);
        Log.i("Amount Entered", EnteredAmount.getText().toString());
  }

LogCat Error Log

       --------- beginning of crash
09-08 22:29:11.790 25239-25239/com.example.admin.convertcurrency E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.admin.convertcurrency, PID: 25239
    java.lang.IllegalStateException: Could not find method clickTextView(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatEditText with id 'EnteredAmount'
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:423)
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:380)
        at android.view.View.performClick(View.java:5215)
        at android.view.View$PerformClick.run(View.java:21196)
        at android.os.Handler.handleCallback(Handler.java:742)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:157)
        at android.app.ActivityThread.main(ActivityThread.java:5603)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)


    --------- beginning of system
09-08 22:29:11.858 25239-25239/com.example.admin.convertcurrency I/Process: Sending signal. PID: 25239 SIG: 9

Upvotes: 1

Views: 1167

Answers (2)

keyboard_kracker22
keyboard_kracker22

Reputation: 71

Perhaps you can use the multiple clickListener for views:

EditText EnteredAmount = (EditText) findViewById(R.id.EnteredAmount);
EnteredAmount.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        Toast.makeText(this, "I am clicked", Toast.LENGTH_SHORT).show;
    }
});

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007099

java.lang.IllegalStateException: Could not find method clickTextView(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatEditText with id 'EnteredAmount'

In your layout, you appear to have android:onClick="clickTextView". In your activity, you do not have a method named clickTextView(). You need to implement that method in your activity:

public void clickTextView(View v) {
 // whatever you want to do
}

Alternatively, you could remove the android:onClick="clickTextView" attribute from your <EditText> in your layout resource.

Upvotes: 4

Related Questions