Apps My program runs...but it doesn't work.

clowmet

Lurker
http://pastebin.com/YmeB2D1N




Essentially, my program has two EditTexts, a Button, and a TextView. You input a number/string into the EditText, and an output is supposed to be shown in the TextView. However, all i get is a 'There is no Department'. How do i fix this?
 

GeorgeN

Well-Known Member
You can't use == to compare the contents of strings, it just checks to see if both pointers reference the same object. Use the String.equals() method instead. For example:
Code:
if (name.equals("Electronics"))
Also when you are testing for the department you could use a switch statement rather than the long sequence of if.. else's.

-George
 

clowmet

Lurker
Thread starter
So, i've tried that. And my project crashed after i tested it on one to see if it would work. Progress?

And i haven't used a switch statement due to time constraints and it giving me an "Cannot convert from int to String" error.
 

GeorgeN

Well-Known Member
What is the logcat output when it crashes?

You can only use a switch to compare against integers so you would have to keep the if...else statements in the name case.

Also, I assume you realise that you are calling setText() twice on the same TextView. The first text you set it to will be lost when you call setText() the second time.

-George
 

clowmet

Lurker
Thread starter
Pid: 280
at dalvik.system.NativeStart.main(Native Method)
at cin.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
 

GeorgeN

Well-Known Member
That's just the bottom two entries of the stack, it doesn't tell you anything much. There should be a load of lines before that which will actually tell you what caused the problem.
 

clowmet

Lurker
Thread starter
That's all it gave me. I also changed the entire top part of it to a switch statement. I'd link you to it, but Pastebin is down.
The console gives me this on top of that.
[2012-04-24 11:52:07 - Unexpected error while launching logcat. Try reselecting the device.] device not found
com.android.ddmlib.AdbCommandRejectedException: device not found
at com.android.ddmlib.AdbHelper.setDevice(AdbHelper.java:752)
at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:373)
at com.android.ddmlib.Device.executeShellCommand(Device.java:397)
at com.android.ddmuilib.logcat.LogCatReceiver$1.run(LogCatReceiver.java:102)
at java.lang.Thread.run(Unknown Source)
 
Top