kotlin

kotlin Get random string from array

断了今生、忘了曾经 提交于 2021-01-29 06:00:23
问题 New to kotlin and quite a few questions and answers, mostly in Java. After following the documentation and verifying against numerous SO questions/answers Android Studio is complaining about the following in a function. The function is fun getRandomQuote() { val randomValue = Random.nextInt(quotes.size) //return quotes[randomValue] return quotes.get(randomValue) } quotes is an arrayOf(strings) val quotes = arrayOf("Alert today – Alive tomorrow.",...) It says for quotes.get(randomValue) That

java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: DefaultDispatcher-worker-2

扶醉桌前 提交于 2021-01-29 05:56:06
问题 I'm quite new about flutter and kotlin. I'm doing flutter version up(from 1.0.0 to 1.7.8+hotfix4) recently. After I upgrade kotlin version to 1.3.10, my flutter app came into crash when I try to start it. And the error shows like this : [ +521 ms] E/AndroidRuntime( 2726): FATAL EXCEPTION: DefaultDispatcher-worker-2 [+1 ms] E/AndroidRuntime( 2726): Process: XXXXXXXXXXXX, PID: 2726 [ ] E/AndroidRuntime( 2726): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the

java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: DefaultDispatcher-worker-2

有些话、适合烂在心里 提交于 2021-01-29 05:50:33
问题 I'm quite new about flutter and kotlin. I'm doing flutter version up(from 1.0.0 to 1.7.8+hotfix4) recently. After I upgrade kotlin version to 1.3.10, my flutter app came into crash when I try to start it. And the error shows like this : [ +521 ms] E/AndroidRuntime( 2726): FATAL EXCEPTION: DefaultDispatcher-worker-2 [+1 ms] E/AndroidRuntime( 2726): Process: XXXXXXXXXXXX, PID: 2726 [ ] E/AndroidRuntime( 2726): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the

Spring Boot/Kotlin ignore value field of @QueryParam

梦想与她 提交于 2021-01-29 05:44:00
问题 I have a Spring Boot/Kotlin web application and a controller that takes a query param. Here's my controller method: import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.ResponseBody import javax.ws.rs.Produces import javax.ws.rs.QueryParam ... @GetMapping("/items") @ResponseBody @Produces(MediaType.APPLICATION_JSON_VALUE) fun getItems(@QueryParam("n") count: Int? = null): Collection<MyItem> { return myItemService.list(count) } The following

Android Kotlin parsing nested JSON

百般思念 提交于 2021-01-29 05:41:47
问题 I'm still pretty new to programming with Kotlin but I can't seem to figure out the correct way to parse my JSON. I'm attempting to get "title" and "body" from "notification" in "unackd" array only. So far I've got: private fun parse(): Boolean { try { val ja = JSONArray(jsonData) var jo: JSONObject users.clear() var user: User for (i in 0 until ja.length()) { jo = ja.getJSONObject(i) val name = jo.getString("title") val username = jo.getString("body") user = User(username,name) users.add(user

AbstractList UnsupportedOperationException when calling .sort on a List

匆匆过客 提交于 2021-01-29 05:40:19
问题 I'm sorting a List using Collections.sort(), which seems to be working every way I can test it. Some of my users are crashing though. Caused by java.lang.UnsupportedOperationException java.util.AbstractList.set (AbstractList.java:681) java.util.AbstractList$FullListIterator.set (AbstractList.java:143) java.util.Collections.sort (Collections.java:1909) com.myapp.MyFragment.myMethod (MyFragment.java:225) But, all I'm doing is trying to sort a List private void myMethod(List<MyThing> myThings) {

Navigating to another fragment from CameraX analyze() blocks current fragment's lifecycle and freezes the UI

送分小仙女□ 提交于 2021-01-29 05:33:56
问题 All my CameraX initializations reside in FragmentA , and my goal is to navigate to FragmentB depending on some condition that must be verified inside analyze() . When navigating directly from analyze() , through Logcat I can see that FragmentB is loaded correctly but the UI freezes on the camera preview, and unfreezes only when I navigate back to FragmentA . I discovered that under those circumstances FragmentA doesn't go through the rest of its lifecycle correctly, meaning that onDestroyView

How to remove first view pager item in kotlin?

那年仲夏 提交于 2021-01-29 05:29:55
问题 I use View-Pager2 in my application that Which displays several same fragments. I also have a dialog fragment and inside it, I manage view pager items(add and remove items). Every fragment inside the view-pager has an id that saved in the SQLite database. So, My problem is, When I remove the first item of view-pager, It does not delete and still remains but another item removed and when I launch the app again, I see the first item has been removed and everything is ok. Main Activity Class:

Android custom view inherit all styles and attributes from parent

♀尐吖头ヾ 提交于 2021-01-29 05:15:17
问题 If you create a custom view that extends a parent view, how can you inherit all styles and attributes from the parent view? For example if I declare a SeekBar in xml and style it, everything works normally. If I extend this view with no additional methods all the default styling and formatting is gone. Original xml. The styling here works as expected: <SeekBar android:id="@+id/seekBar" style="@style/Widget.AppCompat.ProgressBar.Horizontal" android:layout_width="wrap_content" android:layout

Savedstateviewmodelfactory is finall, cannot inherit

别说谁变了你拦得住时间么 提交于 2021-01-29 05:13:47
问题 class SettingsViewModelFactory(application: Application, owner: SavedStateRegistryOwner) : SavedStateViewModelFactory(application, owner){ override fun <T : ViewModel?> create(modelClass: Class<T>): T { if (modelClass.isAssignableFrom(SettingsViewModel::class.java)){ return SettingsViewModel() as T } throw IllegalArgumentException("Invalid ViewModel class") } } I get a red underline below SavedStateViewModelFactory saying that the type is final and cannot be inherited from. What do I do? The