Reputation: 282
When I open the app and use the navigation for the first time it works perfectly and send me to the desired activity. When I then click on one of the tabs in the navigation from the second activity, the whole app crashes. Here is the relevant code:
MainActivity.java
public void CMYKClick(View view) {
Intent intent = new Intent(this, CMYKActivity.class);
startActivity(intent);
}
public void hexClick(View view) {
Intent intent = new Intent(this, hexActivity.class);
startActivity(intent);
}
CMYKActivity.java
public void RGBClickCMYK() {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
public void HexClickCMYK() {
Intent intent = new Intent(this, hexActivity.class);
startActivity(intent);
}
hexActivity.java
public void RGBClickHex() {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
public void CMYKClickHex() {
Intent intent = new Intent(this, CMYKActivity.class);
startActivity(intent);
}
And finally here is the logcat:
08-11 17:17:35.925 2001-2001/com.example.michael.colorpicker E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.michael.colorpicker, PID: 2001
java.lang.IllegalStateException: Could not find a method CMYKClickHex(View) in the activity class com.example.michael.colorpicker.hexActivity for onClick handler on view class android.support.v7.widget.AppCompatButton with id 'CMYKNavBtn'
at android.view.View$1.onClick(View.java:4007)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NoSuchMethodException: CMYKClickHex [class android.view.View]
at java.lang.Class.getMethod(Class.java:664)
at java.lang.Class.getMethod(Class.java:643)
at android.view.View$1.onClick(View.java:4000)
The rest of the logcat wouldn't format properly so I just left it out. If it is necessary I can add it in.
Upvotes: 0
Views: 83
Reputation: 35
Change public void CMYKClickHex()
to public void CMYKClickHex(View view)
.
The view must always be sent when using onClick.
Upvotes: 0
Reputation: 2608
Method name should starts with small letter.
And you have to give onClick in xml file for buttons. method should have view parameter And called methods with same name that the name you have given for onClick attribute.
Something like this:
CMYKActivity.java
public void rgbClickCMYK(View view) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
public void hexClickCMYK(View view) {
Intent intent = new Intent(this, hexActivity.class);
startActivity(intent);
}
Upvotes: 1
Reputation:
Your method signature should be:
public void CMYKClickHex(View view) { ... }
instead of:
public void CMYKClickHex(//Nothing) { ... }
Upvotes: 3