Issue
i have a problem with the "else" in my if-statement. If the statement is correct, my debug-textfield gets the correct text ("YES!"), but if statement is incorrect my app crashes. Could you help me with this please?
Thank you very much in advance!
int a = 1;
int b = 1;
if (isCorrect(a,b)) {
debug.setText("YES!");
} else{
debug.setText("NO!");
}
public static boolean isCorrect(int a, int b){
if(a == b) {
return true;
}else {
return false;
}
}
Here's my logcat: It shows a problem with the int "Res1" which has nothing to do with my if statement. Could this be the problem anyways? But why does it work, if the statement ist true?!
03-11 03:44:54.645 2164-2164/de.test.michael.maths D/dalvikvm﹕ Not late-enabling CheckJNI (already on)
03-11 03:44:54.675 2164-2164/de.test.michael.maths I/System.out﹕ Sending WAIT chunk
03-11 03:44:54.675 2164-2170/de.test.michael.maths E/jdwp﹕ Failed sending reply to debugger: Broken pipe
03-11 03:44:54.675 2164-2170/de.test.michael.maths D/dalvikvm﹕ Debugger has detached; object registry had 1 entries
03-11 03:44:54.675 2164-2164/de.test.michael.maths W/ActivityThread﹕ Application de.test.michael.maths is waiting for the debugger on port 8100...
03-11 03:44:55.865 2164-2170/de.test.michael.maths I/dalvikvm﹕ Debugger is active
03-11 03:44:55.935 2164-2164/de.test.michael.maths I/System.out﹕ Debugger has connected
03-11 03:44:55.935 2164-2164/de.test.michael.maths I/System.out﹕ waiting for debugger to settle...
03-11 03:44:56.145 2164-2164/de.test.michael.maths I/System.out﹕ waiting for debugger to settle...
03-11 03:44:56.355 2164-2164/de.test.michael.maths I/System.out﹕ waiting for debugger to settle...
03-11 03:44:56.565 2164-2164/de.test.michael.maths I/System.out﹕ waiting for debugger to settle...
03-11 03:44:56.775 2164-2164/de.test.michael.maths I/System.out﹕ waiting for debugger to settle...
03-11 03:44:56.985 2164-2164/de.test.michael.maths I/System.out﹕ waiting for debugger to settle...
03-11 03:44:57.195 2164-2164/de.test.michael.maths I/System.out﹕ waiting for debugger to settle...
03-11 03:44:57.405 2164-2164/de.test.michael.maths I/System.out﹕ waiting for debugger to settle...
03-11 03:44:57.615 2164-2164/de.test.michael.maths I/System.out﹕ waiting for debugger to settle...
03-11 03:44:57.825 2164-2164/de.test.michael.maths I/System.out﹕ debugger has settled (1324)
03-11 03:44:57.865 2164-2164/de.test.michael.maths I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
03-11 03:44:57.865 2164-2164/de.test.michael.maths W/dalvikvm﹕ VFY: unable to resolve virtual method 11345: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
03-11 03:44:57.875 2164-2164/de.test.michael.maths D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
03-11 03:44:57.875 2164-2164/de.test.michael.maths I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
03-11 03:44:57.875 2164-2164/de.test.michael.maths W/dalvikvm﹕ VFY: unable to resolve virtual method 11351: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
03-11 03:44:57.875 2164-2164/de.test.michael.maths D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
03-11 03:44:57.875 2164-2164/de.test.michael.maths I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
03-11 03:44:57.875 2164-2164/de.test.michael.maths W/dalvikvm﹕ VFY: unable to resolve virtual method 9039: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
03-11 03:44:57.875 2164-2164/de.test.michael.maths D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
03-11 03:44:57.875 2164-2164/de.test.michael.maths I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
03-11 03:44:57.875 2164-2164/de.test.michael.maths W/dalvikvm﹕ VFY: unable to resolve virtual method 364: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
03-11 03:44:57.875 2164-2164/de.test.michael.maths D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-11 03:44:57.875 2164-2164/de.test.michael.maths I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
03-11 03:44:57.875 2164-2164/de.test.michael.maths W/dalvikvm﹕ VFY: unable to resolve virtual method 386: Landroid/content/res/TypedArray;.getType (I)I
03-11 03:44:57.875 2164-2164/de.test.michael.maths D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-11 03:44:57.955 2164-2164/de.test.michael.maths D/libEGL﹕ loaded /system/lib/egl/libEGL_emulation.so
03-11 03:44:57.955 2164-2164/de.test.michael.maths D/﹕ HostConnection::get() New Host Connection established 0xb89f66a0, tid 2164
03-11 03:44:57.965 2164-2164/de.test.michael.maths D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_emulation.so
03-11 03:44:57.975 2164-2164/de.test.michael.maths D/libEGL﹕ loaded /system/lib/egl/libGLESv2_emulation.so
03-11 03:44:58.025 2164-2164/de.test.michael.maths W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-11 03:44:58.025 2164-2164/de.test.michael.maths D/OpenGLRenderer﹕ Enabling debug mode 0
03-11 03:45:13.395 2164-2164/de.test.michael.maths D/AndroidRuntime﹕ Shutting down VM
03-11 03:45:13.395 2164-2164/de.test.michael.maths W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb0ef3648)
03-11 03:45:13.395 2164-2164/de.test.michael.maths E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NumberFormatException: Invalid int: "Res1"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:375)
at java.lang.Integer.parseInt(Integer.java:366)
at java.lang.Integer.parseInt(Integer.java:332)
at de.test.michael.maths.MainActivity$1.onClick(MainActivity.java:96)
at android.view.View.performClick(View.java:4240)
at android.view.View$PerformClick.run(View.java:17721)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Solution
Try this it worked to me :
public class HelloWorld {
private static int a = 1;
private static int b = 1;
public static void main(String[] args) {
if (isCorrect(a, b)) {
debug.setText("YES!");
}
if (!isCorrect(a, b)) {
debug.setText("NO!");
}
}
public static boolean isCorrect(int a, int b) {
boolean ok = false;
if (a == b) {
ok = true;
}
return ok;
}
}
Answered By - Skizo-ozᴉʞS
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.