mercredi 21 février 2018

App is crashing after looking for EditText.isEmpty()

I don't even understand what's is this and why it doesn't work ok. I have button, which starts new activity. But before it, I check some values, and after clicking on the button - it's crashing .-. I don't know what to do, it doesn't work properly anyway. I'm writing on Code:

lateinit var string: String
var day: Int = 0
var month: Int = 0
var yearProp: Int = 0
var dayEnd: Int = 0
var monthEnd: Int = 0
var yearEndProp: Int = 0
var priceFrom: Int = 0
var priceTo: Int = 0
companion object {
    lateinit var props: Properties
}

override fun onDateSet(view: DatePickerDialog?, year: Int, monthOfYear: Int, dayOfMonth: Int, yearEnd: Int, monthOfYearEnd: Int, dayOfMonthEnd: Int) {
    day = dayOfMonth
    month = monthOfYear
    yearProp = year
    dayEnd = dayOfMonthEnd
    monthEnd = monthOfYearEnd
    yearEndProp = yearEnd
    button_whats_date.text = getString(R.string.title_from) + ": " + day + "/" + month + "/" + yearProp + " | " + getString(R.string.title_to) + ": " + dayEnd + "/" + monthEnd + "/" + yearEndProp
}    

param_done.setOnClickListener {
        if (input_price_from.getText().toString().matches("".toRegex()) || input_price_to.getText().toString().matches("".toRegex())) {
            priceFrom = 0; priceTo = 999999999
            Log.i("VALUES", "" + priceTo)
            if (Integer.parseInt(input_price_from.text.toString()) > Integer.parseInt(input_price_to.text.toString())) {
                Toast.makeText(this@MainActivity, getString(R.string.error_change_price), LENGTH_SHORT).show()
            } else {
                try {
                    props = Properties(string, int, int, int, int, int, int, priceFrom, priceTo)
                    val intent = Intent(this@MainActivity, SearchActivity::class.java)
                    startActivity(intent)
                } catch (e: Throwable) {
                    Toast.makeText(this@MainActivity, getString(R.string.props_error), LENGTH_SHORT).show()
                    Log.i("Hereissometex", "User cannot follow to next activity")
                }
            }
        }
    }


<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="12dp"
            android:layout_marginHorizontal="8dp"
            android:orientation="horizontal">
            <EditText
                android:id="@+id/input_price_from"
                android:inputType="number"
                android:layout_width="0dp"
                android:layout_height="60dp"
                android:layout_weight="2"
                android:textColor="#FFF"
                android:hint="@string/title_from"/>
            <EditText
                android:id="@+id/input_price_to"
                android:inputType="number"
                android:layout_width="0dp"
                android:layout_height="60dp"
                android:layout_weight="2"
                android:textColor="#FFF"
                android:hint="@string/title_to"/>
        </LinearLayout>
    </LinearLayout>
    <Button
        android:id="@+id/param_done"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|bottom"
        android:layout_marginBottom="10dp"
        android:background="@android:color/transparent"
        android:text="@string/done"
        android:textColor="@color/colorPrimary"/>
</FrameLayout>

And it's just crashing down. If you need something else - just give me a sign. There is how I do check input values:

input_price_from.addTextChangedListener(object : TextWatcher {
        override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
        override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
        override fun afterTextChanged(s: Editable) {
            priceFrom = Integer.parseInt(input_price_from.text.toString())
            Log.i("[TravelMet::INFO]", "InputPrice value changed and parced")
        }
    })
    input_price_to.addTextChangedListener(object : TextWatcher {
        override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
        override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
        override fun afterTextChanged(s: Editable) {
            priceTo = Integer.parseInt(input_price_to.text.toString())
            Log.i("[TravelMet::INFO]", "InputPrice value changed and parced")
        }
    })

Aucun commentaire:

Enregistrer un commentaire