1. Are you ready for the Galaxy S20? Here is everything we know so far!

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

Discussion in 'Android Development' started by clowmet, Apr 21, 2012.

  1. clowmet

    clowmet Lurker
    Thread Starter

    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?
     



    1. Download the Forums for Android™ app!


      Download

       
  2. GeorgeN

    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 (Text):
    1. 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
     
  3. clowmet

    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.
     
  4. GeorgeN

    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
     
  5. clowmet

    clowmet Lurker
    Thread Starter

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

    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.
     
  7. clowmet

    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)
     
Loading...

Share This Page

Loading...