Julian Julian - 5 months ago 35
Android Question

What does this errormessage mean?

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.juliandrach.eatfit, PID: 2223
java.lang.IllegalStateException: Could not find method aldirindersalami(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:327)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

Basically the error occurs when I am updating a variable by pressing a button and then trying to display the value of the variable with a toast in the same task.

public class Mahlzeiten extends AppCompatActivity {

public static int proteine = 0;
public static int carbs = 0;
public static int fette = 0;
public static int kcal = 0;

protected void onCreate(Bundle savedInstanceState) {
String text = "Hallo" + proteine + "danke";
Toast.makeText(Mahlzeiten.this, text, Toast.LENGTH_SHORT).show();
public void aldirindersalami (int proteine){
// String text1 = "Hallo" + proteine + "danke";
// Toast.makeText(Mahlzeiten.this, text1, Toast.LENGTH_SHORT).show();


You have an onClick listener set in the xml but you didn't implement the onClick method in the code. You need the following method

public void aldirindersalami(View v) {}

to handle the click on the button.