Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] I am learning Android studio and doing a rectangle calculator, my kotlin has 19 errors and cannot figure it out

Posted on November 11, 2022 By

Solution 1 :

If you want to access the views from your XML file directly in your activity you should use Kotlin Android Extension. But this plugin is deprecated. You should migrate to View Binding.

https://developer.android.com/topic/libraries/view-binding/migration

Problem :

I am learning Android studio and doing a rectangle calculator. My Kotlin has 19 errors, and I cannot figure it out. I keep getting unresolved errors for btn, functions that cannot be called, and expecting an element. I am trying to do a calculator that takes height and width and then calculates area and perimeter. Just need guidance on what I am doing wrong and not looking for someone to give me new code.

MainActivity.kt

package com.example.calculator

import android.annotation.SuppressLint
import android.icu.text.DecimalFormat
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.*

class MainActivity : AppCompatActivity() {

    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        btn_calculate.setOnClickListener {
            calculate()
            btn_calculate.onEditorAction(EditorInfo.IME_ACTION_DONE)
        }
        btn_reset.setOnClickListener {
            reset()
        }
    }
    private fun calculate() {
        val formatter = DecimalFormat("#.##")
        val editNum1 = (EditText) editNum1.text.toString()
        val editNum2 = (EditText) editNum2.text.toString()

        val Area = DecimalFormat(editNum1.toDouble() * editNum2.toDouble())
        val Perimeter = DecimalFormat(2* ( (editNum1.toDouble()) + (editNum2.toDouble()))
    }}

Comments

Comment posted by Elango

Can you show the error to us

Comment posted by Abhishek Dutt

Post the stack trace or the error log you are getting.

Comment posted by Abhishek Dutt

Seems like you forgot to define

Comment posted by deprecated

Kotlin extensions is

Comment posted by Jensy

sorry for sounding dumb but I just started Android studio this week and it is an online course and the text book used is from 2015. So Kotlin extension in the import library is no longer used and I have to do view-binding?

Comment posted by cactustictacs

@Jensy yeah the synthetic binding stuff was a bit “magical” and it’s been deprecated for a long time – the good news is View Binding works almost exactly the same way, you just have to explicitly create a binding object and reference all your views on that. So

READ  [FIXED] android - TextView Id keeps calling on null no matter what way I try to change its content
Powered by Inline Related Posts

Comment posted by Jensy

Thank you will try the steps

Android Tags:android, android-studio, calculator, kotlin

Post navigation

Previous Post: [FIXED] React-native android build fails due to missing files in the gradle cache?
Next Post: Can I use Google storage instead of iCloud?

Related Posts

[FIXED] Testing fragment: I keep getting java.lang.RuntimeException: android.view.InflateException Android
[FIXED] android – prevent multiple checks from being selected in recycleview kotlin Android
[FIXED] java – NullPointerException in adapter holding viewholders Android
[FIXED] android – Invariant viloation: Objects are not valid as a React child(found: object with keys {fontweight, fontsize}) Android
[FIXED] android – Picture is not showing up in my activity after I take a photo Android
[FIXED] android – Creating mutiple markers on google maps in compose Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Quel est le fromage qui porte le nom d’une commune de Côte d’Or et qui est produit en Haute-marne ?
  • Welches ist das beste Senioren Smartphone?
  • What is ISO benefit?
  • What do red bottom shoes represent?
  • Are ultrasonic cleaners safe for electronics?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme