MainActivity.kt
Код: Выделить всё
package com.example.lightning
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.example.lightning.data.Location
import com.example.lightning.data.Profile
import com.example.lightning.ui.theme.LightningTheme
import com.example.lightning.ui2.ProfileCard
import com.example.lightning.ui2.login.EmailLoginScreen
import com.example.lightning.ui2.login.LoginScreen
import androidx.compose.foundation.lazy.LazyColumn
import com.example.lightning.ui2.login.RegistrationScreen
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
LightningTheme {
val navController = rememberNavController()
NavHost(navController = navController, startDestination = "login_screen") {
composable("login_screen") { LoginScreen(navController) }
composable("email_login_screen") { EmailLoginScreen(navController) }
composable("profile_screen") { ProfileScreen(getDummyProfileData()) }
composable("registration_screen") { RegistrationScreen(navController) }
}
}
}
}
// Function to get sample profile data (replace with your data source)
private fun getDummyProfileData(): List
{
return listOf(
Profile(
id = "1",
name = "Alice Johnson",
age = 28,
imageUrl = "https://via.placeholder.com/150", // Placeholder image URL
bio = "Loves hiking, traveling, and trying new foods.",
gender = "Female",
interests = listOf("Hiking", "Traveling", "Cooking"),
location = Location("San Francisco", "California", "USA"),
occupation = "Software Engineer",
education = "Master's Degree",
relationshipStatus = "Single",
lookingFor = "Serious relationship"
),
Profile(
id = "2",
name = "Bob Smith",
age = 32,
imageUrl = "https://via.placeholder.com/150",
bio = "Enjoys playing guitar, watching movies, and exploring new places.",
gender = "Male",
interests = listOf("Music", "Movies", "Travel"),
location = Location("New York", "New York", "USA"),
occupation = "Musician",
education = "Bachelor's Degree",
relationshipStatus = "Single",
lookingFor = "Casual dating"
),
// Add more dummy profiles here...
)
}
@Composable
fun ProfileScreen(profiles: List) {
LightningTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
LazyColumn {
items(profiles.size) { index ->
ProfileCard(profiles[index])
}
}
}
}
}
}
Код: Выделить всё
package com.example.lightning.ui2 // Adjust if your package is different
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.example.lightning.R
import com.example.lightning.data.Profile
@Composable
fun ProfileCard(profile: Profile) {
Card(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
elevation = CardDefaults.cardElevation(defaultElevation = 8.dp),
colors = CardDefaults.cardColors(Color(0xFF000000)),
) {
Row(
modifier = Modifier
.padding(16.dp)
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
//Profile Image
AsyncImage(
model = profile.imageUrl,
contentDescription = "Profile Image",
placeholder = painterResource(id = R.drawable.error_image),
error = painterResource(id = R.drawable.placeholder_image),
modifier = Modifier
.size(80.dp)
.clip(CircleShape),
contentScale = ContentScale.Crop
)
Spacer(modifier = Modifier.width(16.dp))
Column {
Text(text = profile.name, style = MaterialTheme.typography.headlineSmall, fontWeight = FontWeight.Bold, color = Color.White)
Text(text = "${profile.age}", style = MaterialTheme.typography.bodyMedium, color = Color.White)
// Add more Text composables for other profile details
}
}
}
}
Код: Выделить всё
FATAL EXCEPTION: main
Process: com.example.lightning, PID: 8673
android.content.res.Resources$NotFoundException: Resource ID #0x7f07006e
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:240)
at android.content.res.Resources.getValue(Resources.java:1511)
at androidx.compose.ui.res.PainterResources_androidKt.painterResource(PainterResources.android.kt:61)
at com.example.lightning.ui2.ProfileCardKt$ProfileCard$1.invoke(ProfileCard.kt:39)
at com.example.lightning.ui2.ProfileCardKt$ProfileCard$1.invoke(ProfileCard.kt:27)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:118)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.material3.CardKt$Card$1.invoke(Card.kt:886)
at androidx.compose.material3.CardKt$Card$1.invoke(Card.kt:93)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.material3.SurfaceKt$Surface$1.invoke(Surface.kt:134)
at androidx.compose.material3.SurfaceKt$Surface$1.invoke(Surface.kt:115)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
at androidx.compose.material3.SurfaceKt.Surface-T9BRK9s(Surface.kt:112)
at androidx.compose.material3.CardKt.Card(Card.kt:85)
at com.example.lightning.ui2.ProfileCardKt.ProfileCard(ProfileCard.kt:21)
at com.example.lightning.MainActivity$ProfileScreen$1$1$1$1.invoke(MainActivity.kt:83)
at com.example.lightning.MainActivity$ProfileScreen$1$1$1$1.invoke(MainActivity.kt:82)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:139)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.foundation.lazy.LazyListItemProviderImpl$Item$1.invoke(LazyListItemProvider.kt:79)
at androidx.compose.foundation.lazy.LazyListItemProviderImpl$Item$1.invoke(LazyListItemProvider.kt:77)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:248)
at androidx.compose.foundation.lazy.layout.LazyLayoutPinnableItemKt.LazyLayoutPinnableItem(LazyLayoutPinnableItem.kt:58)
at androidx.compose.foundation.lazy.LazyListItemProviderImpl.Item(LazyListItemProvider.kt:77)
at androidx.compose.foundation.lazy.layout.LazyLayoutItemContentFactoryKt$SkippableItem$1.invoke(LazyLayoutItemContentFactory.kt:135)
at androidx.compose.foundation.lazy.layout.LazyLayoutItemContentFactoryKt$SkippableItem$1.invoke(LazyLayoutItemContentFactory.kt:134)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:248)
at androidx.compose.runtime.saveable.SaveableStateHolderImpl.SaveableStateProvider(SaveableStateHolder.kt:84)
at androidx.compose.foundation.lazy.layout.LazySaveableStateHolder.SaveableStateProvider(LazySaveableStateHolder.kt:85)
at androidx.compose.foundation.lazy.layout.LazyLayoutItemContentFactoryKt.SkippableItem-JVlU9Rs(LazyLayoutItemContentFactory.kt:134)
at androidx.compose.foundation.lazy.layout.LazyLayoutItemContentFactoryKt.access$SkippableItem-JVlU9Rs(LazyLayoutItemContentFactory.kt:1)
at androidx.compose.foundation.lazy.layout.LazyLayoutItemContentFactory$CachedItemContent$createContentLambda$1.invoke(LazyLayoutItemContentFactory.kt:101)
- Очистка и восстановление сборки
- попытка do file -> Недействительные кеши/Перезапустить, а затем перезапустить Android Studio.
- добавление val resourcesId = resources.getIdentifier("my_resource_name", "id", packageName) в MainActivity. kt и пересоберите, но проблема все еще сохраняется.
Подробнее здесь: https://stackoverflow.com/questions/785 ... 0x7f07006e