Mousa388
Mousa388

Reputation: 11

Could not find method value(View) in a parent or ancestor Context for android:onClick

i am having this error with my application can anyone please helpme

 button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                num1 = Integer.parseInt(value.getText().toString());
                result_num= num1 * 0.05 ;


                text1.setText(String.valueOf(result_num));
            }


        });

this is the xml file



    <EditText
        android:id="@+id/value"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/toolbar"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="108dp"
        android:ems="10"
        android:hint="المبلغ"
        android:inputType="number|numberDecimal"
        android:onClick="value" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/value"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="27dp"
        android:fadingEdge="horizontal|vertical"
        android:fontFamily="sans-serif-smallcaps"
        android:foregroundGravity="top|left"
        android:gravity="center"
        android:onClick="button"
        android:text="أحسب"
        android:textColor="@color/colorAccent"
        android:textSize="24sp"
        android:typeface="normal" />


and this is the error

2020-04-27 03:02:40.286 3179-3179/? E/com.aaaaaa: Unknown bits set in runtime_flags: 0x8000 2020-04-27 03:05:03.137 3179-3179/com.taxcal.tax E/AndroidRuntime: FATAL EXCEPTION: main Process: com.aaaaa, PID: 3179 java.lang.IllegalStateException: Could not find method value(View) in a parent or ancestor Context for android:onClick attribute defined on view class androidx.appcompat.widget.AppCompatEditText with id 'value'

Upvotes: 0

Views: 1075

Answers (2)

A P Harivignesh
A P Harivignesh

Reputation: 21

Make sure the "value" and "button" methods are declared as public.

Upvotes: 1

Alan Deep
Alan Deep

Reputation: 2105

Just remove android:onClick="value" and also android:onClick="button" from your layout

Upvotes: 0

Related Questions