我正在尝试使用以下内容中的撰写视图填充底部对话框AppCompatActivity:
val bottomSheet = BottomSheetDialog(this)
bottomSheet.setContentView(ComposeView(this).apply {
setContent {
MaterialTheme {
Test()
}
}
})
bottomSheet.show()
Run Code Online (Sandbox Code Playgroud)
使用androidx.fragment:fragment-ktx:1.4.0-alpha10,androidx.appcompat:appcompat:1.3.1
出现以下异常:
java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from android.widget.FrameLayout{386906d V.E...... ......I. 0,0-0,0 #7f0900d3 app:id/container}
at androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareViewTreeRecomposer(WindowRecomposer.android.kt:244)
at androidx.compose.ui.platform.WindowRecomposer_androidKt.access$createLifecycleAwareViewTreeRecomposer(WindowRecomposer.android.kt:1)
at androidx.compose.ui.platform.WindowRecomposerFactory$Companion$LifecycleAware$1.createRecomposer(WindowRecomposer.android.kt:99)
at androidx.compose.ui.platform.WindowRecomposerPolicy.createAndInstallWindowRecomposer$ui_release(WindowRecomposer.android.kt:155)
at androidx.compose.ui.platform.WindowRecomposer_androidKt.getWindowRecomposer(WindowRecomposer.android.kt:230)
at androidx.compose.ui.platform.AbstractComposeView.resolveParentCompositionContext(ComposeView.android.kt:220)
at androidx.compose.ui.platform.AbstractComposeView.ensureCompositionCreated(ComposeView.android.kt:227)
at androidx.compose.ui.platform.AbstractComposeView.onAttachedToWindow(ComposeView.android.kt:259)
at android.view.View.dispatchAttachedToWindow(View.java:19553)
...
Run Code Online (Sandbox Code Playgroud) 我想知道这是否可以作为流函数更整洁地编写:
MyObject myObject = new MyObject();
for (Thing thing : listofThings) {
myObject = myObject.combine(thing);
}
Run Code Online (Sandbox Code Playgroud) 我是C的新手,我在使用结构时遇到了麻烦.我有以下代码:
typedef struct uint8array {
uint8 len;
uint8 data[];
} uint8array;
int compare_uint8array(uint8array* arr1, uint8array* arr2) {
printf("%i %i\n data: %i, %i\n", arr1->len, arr2->len, arr1->data[0], arr2->data[0]);
if (arr1->len != arr2->len) return 1;
return 0;
}
int compuint8ArrayTest() {
printf("--compuint8ArrayTest--\n");
uint8array arr1;
arr1.len = 2;
arr1.data[0] = 3;
arr1.data[1] = 5;
uint8array arr2;
arr2.len = 4;
arr2.data[0] = 3;
arr2.data[1] = 5;
arr2.data[2] = 7;
arr2.data[3] = 1;
assert(compare_uint8array(&arr1, &arr2) != 0);
}
Run Code Online (Sandbox Code Playgroud)
现在这个程序的输出是:
--compuint8ArrayTest--
3 4
data: 5, 3
Run Code Online (Sandbox Code Playgroud)
为什么值不是我初始化它们的值?我在这里错过了什么?