A
A
Amir Utemissov2018-11-14 16:40:12
Android
Amir Utemissov, 2018-11-14 16:40:12

Where is the mistake? Why doesn't the application start on Android studio?

Tell me why the application does not start? (Is there a mistake here?)

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".Main">

    <EditText
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:id="@+id/etNum1"
            android:layout_width="196dp"
            android:inputType="numberDecimal" android:layout_marginTop="8dp"
            app:layout_constraintTop_toTopOf="parent" android:layout_marginStart="5dp"
            app:layout_constraintStart_toStartOf="parent"
            android:importantForAutofill="no"
            tools:ignore="LabelFor">

    </EditText>
    <EditText
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:id="@+id/etNum2"
            android:layout_width="174dp"
            android:inputType="numberDecimal"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="5dp" android:layout_marginTop="8dp" app:layout_constraintTop_toTopOf="parent"
            android:autofillHints="" tools:ignore="LabelFor">

    </EditText>
    <Button
            android:text="@string/result"
            android:layout_width="129dp"
            android:layout_height="44dp"
            android:id="@+id/btnDiv"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="8dp"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginStart="8dp"
            android:layout_marginTop="64dp"
            app:layout_constraintTop_toTopOf="parent" >

    </Button>

    <TextView
            android:text="@string/Ответ"
            android:layout_width="273dp"
            android:layout_height="35dp"
            android:id="@+id/tvResult"
            android:layout_marginTop="128dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="8dp"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginStart="8dp" app:layout_constraintHorizontal_bias="0.505" tools:text="Ответ">

    </TextView>


</android.support.constraint.ConstraintLayout>

package com.example.coolyet.zerde
import android.annotation.SuppressLint
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.view.View
import android.widget.Button
import android .widget.EditText
import android.widget.TextView
abstract class Main : AppCompatActivity(), View.OnClickListener {
internal lateinit var etNum1: EditText
internal lateinit var etNum2: EditText
internal lateinit var btnDiv: Button
internal abstract var tvResult: TextView
public override fun onCreate (savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// find elements
this.etNum1 = this.findViewById(R.id.etNum1)
this.etNum2 = findViewById(R.id.etNum2)
this.btnDiv = findViewById(R.id.btnDiv)
this.tvResult = findViewById(R.id.tvResult)
// set handler
btnDiv.setOnClickListener(this)
}
@SuppressLint("SetTextI18n")
override fun onClick(v: View) {
val num1: Number
val num2: Number
var result = 0f
// Check if fields are empty
if (TextUtils.isEmpty(etNum1.text.toString()) || TextUtils.isEmpty(etNum2.text.toString())) {
return
}
// read EditText and fill variables with numbers
num1 = java.lang.Float.parseFloat(etNum1.text.toString())
num2 = java.lang.Float.parseFloat(etNum2.text.toString())
// determine pressed button and perform the corresponding operation
// write the operation in oper, then we will use it in the output
when (v.id) {
R.id.btnDiv -> {
result = 4 / 100 * num1 / num2
}
else -> {
}
}
// form the output string
tvResult.text = num1.toString() + result
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bask, 2018-11-14
@bask

Why is the class abstract?
Learn OOP.
Is it in the activity manifest?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question