Wie behebe ich den Fehler „Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), Fault addr 0x20 in tid 19443 (RenderThread)“Android

Forum für diejenigen, die für Android programmieren
Guest
 Wie behebe ich den Fehler „Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), Fault addr 0x20 in tid 19443 (RenderThread)“

Post by Guest »

Immer wenn ich versuche, vom untenstehenden Bildschirm zurück zu navigieren, kommt es zu einem Absturz.

Code: Select all

@OptIn(
ExperimentalFoundationApi::class,
ExperimentalMaterial3Api::class
)
@Composable
fun MailRoomScreen(
navController: NavHostController,
mailroomViewModel: MailroomViewModel = hiltViewModel()
) {
val context = LocalContext.current
val appNavigationActions = AppNavigationActions(navController)
val webView = remember { WebView(context) }
val tabs by mailroomViewModel.tabs.collectAsState()
val pagerState = rememberPagerState(
initialPage = 0,
initialPageOffsetFraction = 0f,
pageCount = {
tabs.size
}
)

val scope = rememberCoroutineScope()

LaunchedEffect(tabs) {
if (pagerState.currentPage !in tabs.indices) {
pagerState.scrollToPage(0)
}
}

LaunchedEffect(Unit) {
mailroomViewModel.getTabs()
}

Scaffold(
topBar = {
TopAppBar(
title = {
Text(
text = "Mailroom"
)
},
navigationIcon = {
IconButton(
onClick = {
webView.destroy()
navController.popBackStack()
}
) {
Icon(
Icons.Filled.ArrowBack,
contentDescription = "Back"
)
}
},
actions = {
Icon(
Icons.Rounded.AddAlert,
contentDescription = "Notify",
modifier = Modifier.size(30.dp)
)

},
colors = TopAppBarDefaults.topAppBarColors(
containerColor = materialColor,
titleContentColor = Color.White,
navigationIconContentColor = Color.White,
actionIconContentColor = Color.White
)
)
},
floatingActionButton = {
if (tabs.isNotEmpty()) {
// Add a floating action button on both the tabs
when (pagerState.currentPage) {
0 -> {
FloatingActionButton(
onClick = {
val jsonObject1 = JsonObject()
jsonObject1.addProperty("formId", "in")
val jsonString = jsonObject1.toString()
navController.navigate(
Destinations.MAILROOM_FORM_ROUTE.replace(
oldValue = "{jsonString}",
newValue = URLEncoder.encode(jsonString, "utf-8")
)
) {
popUpTo(Destinations.MAILROOM_FORM_ROUTE) {
inclusive = true
}
}
},
containerColor = Color(0xFF006164),
contentColor = Color.White
) {
Icon(
Icons.Filled.Add,
contentDescription = "Add"
)
}
}

1 ->  {
FloatingActionButton(
onClick = {
val jsonObject = JsonObject()
jsonObject.addProperty("formId", "out")
val jsonString = jsonObject.toString()
navController.navigate(
Destinations.MAILROOM_FORM_ROUTE.replace(
oldValue = "{jsonString}",
newValue = URLEncoder.encode(jsonString, "utf-8")
)
) {
popUpTo(Destinations.MAILROOM_FORM_ROUTE) {
inclusive = true
}
}
},
containerColor = Color(0xFF006164),
contentColor = Color.White
) {
Icon(
Icons.Filled.Add,
contentDescription = "Add"
)
}
}
}
}
}
) { paddingValues ->
Column {
// TabRow below the TopAppBar
if (tabs.isNotEmpty() && pagerState.currentPage in tabs.indices) {
TabRow(
selectedTabIndex = pagerState.currentPage,
containerColor = materialColor,
contentColor = Color.White,
modifier = Modifier.padding(paddingValues),
indicator = { tabPositions ->
if (pagerState.currentPage in tabPositions.indices) {
SecondaryIndicator(
Modifier
.padding(
start = 10.dp,
end = 10.dp
)
.tabIndicatorOffset(tabPositions[pagerState.currentPage]),
height = 4.dp,
color = Color.White
)
}
}
) {
tabs.forEachIndexed { index, title ->
Tab(
selected = pagerState.currentPage == index,
onClick = {
scope.launch {
pagerState.animateScrollToPage(index)
}
},
text = {
Text(
text = title,
style = MaterialTheme.typography.bodyMedium
)
},
selectedContentColor = Color.White,
unselectedContentColor = Color.White,
)
}
}

HorizontalPager(
state = pagerState,
modifier = Modifier.fillMaxSize()
) {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
when (it) {
0 -> {
MailRoomInScreen(
webView = webView,
mailRoomViewModel = mailroomViewModel,
navController = navController
)
//Text(text = "In")
}
1 ->  Text(text = "Out")
}
}
}
} else {
// Handle the empty state or invalid pager state
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Text(text = "No tabs available")
}
}
}
}
}

Code: Select all

@Composable
fun MailRoomInScreen(
webView: WebView,
mailRoomViewModel: MailroomViewModel,
navController: NavHostController
) {
val context = LocalContext.current
val mailRoomLogs by mailRoomViewModel.mailRoomLogs.collectAsState()
val type = "inTab"

val appNavigationActions = AppNavigationActions(navController)

// Initialize the WebView
val webView = remember {
WebView(context).apply {
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
addJavascriptInterface(
MailRoomListInterface(navController, mailRoomViewModel, this, context),
"Android"
)
webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
val jsonData = convertToJson(mailRoomLogs, type)
view?.evaluateJavascript("showList($jsonData)") { result ->
Log.d("Result", result)
}
}
}
loadUrl(BaseUrls.ListUrl)
}
}

// Dispose of the WebView when the composable is removed from the composition
DisposableEffect(Unit) {
onDispose {
webView.loadData("", "text/html", "base64")
webView.destroy()
}
}

// Load mail room logs when the composable is first composed
LaunchedEffect(Unit) {
mailRoomViewModel.getMailRoomLogs()
}

// Display the WebView
AndroidView(
factory = { webView },
modifier = Modifier.fillMaxSize()
)
}
Aber wenn ich den Tab-Bildschirm durch einen einfachen zusammensetzbaren Text ersetze, verschwindet das Problem. Als ich die Dokumentation überprüfte, wurde mir Android Native Crash angezeigt, aber ich konnte das Problem immer noch nicht lösen.
Ich wollte vom aktuellen Bildschirm zurück navigieren, aber während ich das tat, es kommt zu einem Absturz.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post