最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

kotlin - Android Build Fails to launch app on current version of Android application - Stack Overflow

programmeradmin7浏览0评论

I have finished the current (base model) of my ToDoList App, but the app fails to launch after I build & refresh (on Android Studio). I don't know what errors my code currently has, that it fails to launch properly as an app when the build runs. I have added a number of imports, added code fixes, and have tried restarting my Android Studio IDE multiple times.

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activitypose.setContent
import androidx.activity.enableEdgeToEdge
import androidxpose.foundation.layout.Arrangement
import androidxpose.foundation.layout.Column
import androidxpose.foundation.layout.Row
import androidxpose.foundation.layout.fillMaxSize
import androidxpose.foundation.layout.fillMaxWidth
import androidxpose.foundation.layout.padding
import androidxpose.foundation.lazy.LazyColumn
import androidxpose.foundation.lazy.items
import androidxpose.material3.Button
import androidxpose.material3.HorizontalDivider
import androidxpose.material3.MaterialTheme
import androidxpose.material3.OutlinedTextField
import androidxpose.material3.Scaffold
import androidxpose.material3.Surface
import androidxpose.material3.Text
import androidxpose.runtime.Composable
import androidxpose.runtime.getValue
import androidxpose.runtime.mutableStateListOf
import androidxpose.runtime.mutableStateOf
import androidxpose.runtime.remember
import androidxpose.runtime.setValue
import androidxpose.ui.Alignment
import androidxpose.ui.Modifier
import androidxpose.ui.text.font.FontWeight
import androidxpose.ui.tooling.preview.Preview
import androidxpose.ui.unit.dp
import androidxpose.ui.unit.sp
import com.example.firstapriltemplate.ui.theme.FirstAprilTemplateTheme

@Composable
fun App() {
    var item by remember { mutableStateOf("") }
    val items = remember { mutableStateListOf<String>() }

    FirstAprilTemplateTheme {
        Column(modifier = Modifier.fillMaxSize()) {
            Text(
                text = "To Do List!",
                fontSize = 32.sp,
                fontWeight = FontWeight.Bold,
                modifier = Modifier.padding(12.dp)
            )

            Row() {
                OutlinedTextField(
                    value = item,
                    onValueChange = { item = it },
                    label = { Text(text = "New Item") }
                )

                Button(onClick = {
                    if (item.isNotEmpty()) {
                        items.add(item) // new item add
                        item = ""
                    }
                }, modifier = Modifier.padding(14.dp)) {
                    Text(text = "Save")
                }
            }
            HorizontalDivider()

            LazyColumn {
                items(items) { task ->
                    ToDoListItem(name = task)
                }
            }
        }
    }
}


@Composable
fun ToDoListItem(name: String) {
    Surface(
        color =  MaterialTheme.colorScheme.background,

        ) {
        Text(text = name, modifier = Modifier.padding(12.dp))
        HorizontalDivider()
    }
}

@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
    App()
}
发布评论

评论列表(0)

  1. 暂无评论