Android - 如果那时不起作用..?

时间:2015-06-14 21:43:07

标签: java android

我在这里撞墙。我得到了这个检查数据库结果的代码:

chosenSlotDAO.open();
        Log.d("id", chosenSlotDAO.getId());
        Log.d("isParked", chosenSlotDAO.getIsParked());
        Log.d("parkedRow", chosenSlotDAO.getParkedRow());
        Log.d("selectedSlot", chosenSlotDAO.getSelectedSlot());
        String idStatus = chosenSlotDAO.getId();
        String isParkedStatus = chosenSlotDAO.getIsParked();
        String parkedRowStatus = chosenSlotDAO.getParkedRow();
        String selectedSlotStatus = chosenSlotDAO.getSelectedSlot();
        final String outputA = this.getOutput(this, slotA);

        if(idStatus == id && isParkedStatus == isParked && parkedRowStatus != parkedA && selectedSlotStatus != slotA)
        {
            arriveTView.setText(alreadyParked + chosenSlotDAO.getParkedRow());
        }
        else if(idStatus == id && isParkedStatus == isNotParked && parkedRowStatus != parkedA && selectedSlotStatus != slotA)
        {
            Toast.makeText(getApplicationContext(), 
                wrongParkingRow, 
                Toast.LENGTH_LONG).show();
            chosenSlotDAO.updateSlot(id, slotA, parkedA, isParked);
        }
        else if(idStatus == id && isParkedStatus == isParked && parkedRowStatus == parkedA && selectedSlotStatus == slotA)
        {
            chosenSlotDAO.updateSlot(id, slotA, setEmpty, isNotParked);

            dbUpdateAdd.execute(slotA);
            Intent myIntent = new Intent(ParkAArrive.this, ParkLeaving.class);
            ParkAArrive.this.startActivity(myIntent);
        }
        else if(outputA.isEmpty())
        {
            arriveTView.setText(isFull);
        }

        else
        {
            Toast.makeText(getApplicationContext(), 
                    nowParked, 
                    Toast.LENGTH_LONG).show();
            chosenSlotDAO.updateSlot(id, slotA, parkedA, isParked);
            arriveTView.setText(chosenSlotDAO.getSelectedSlot());
            dbUpdate.execute(slotA);
        }

通过点击NFC标签启动课程。

LogCat返回:

06-15 04:35:10.818: D/id(12294): 1
06-15 04:35:10.818: D/isParked(12294): 1
06-15 04:35:10.819: D/parkedRow(12294): ParkedA
06-15 04:35:10.819: D/selectedSlot(12294): SlotA
06-15 04:35:10.829: D/link(12294): http://parkit.byethost9.com/db_show_slot.php?slot_name=SlotA
06-15 04:35:11.681: D/line(12294): 14

它清楚地显示用户停放,parkedRow是ParkedA,SlotA是SlotA。但是if不起作用。

但是当我再次开始活动时,除了

之外什么都没有
else if(outputA.isEmpty())
        {
            arriveTView.setText(isFull);
        }

        else
        {
            Toast.makeText(getApplicationContext(), 
                    nowParked, 
                    Toast.LENGTH_LONG).show();
            chosenSlotDAO.updateSlot(id, slotA, parkedA, isParked);
            arriveTView.setText(chosenSlotDAO.getSelectedSlot());
            dbUpdate.execute(slotA);
        }

作品。

代码中的哪个位置我做错了?如果我留下任何必要的信息,请告诉我..

更新: 我似乎需要更改我的代码,以便它可以比较String,是的,这是我面临的问题。

1 个答案:

答案 0 :(得分:1)

您应该使用equals方法来比较String个对象而不是the == operator

有关完整说明,请参阅以下问题:How do I compare strings in Java?