RuntimeException on initialising while offline
When a device is offline and tries to initialise a viewmdodel like the ChannelListViewmodel, it throws a fatal RuntimeException with message Cannot create an instance of class com.getstream.sdk.chat.viewmodel.ChannelListViewModel
@Chikrix do you have full stack trace? And do you have steps to reproduce? Sample app works correctly without network.
View models are created internally by ViewModelProviders, so I doubt that it is somehow connected with offline mode. Also the most obvious reason is absence of public constructor: https://stackoverflow.com/questions/44998051/cannot-create-an-instance-of-class-viewmodel ChannelListViewModel has it.
Closing it as inactive.
java.lang.RuntimeException: Cannot create an instance of class com.getstream.sdk.chat.viewmodel.ChannelListViewModel i am getting this error whenever i try to assign viewmodel
Hello @abhirup-patra do you have full stack trace? Could you provide code where you create and assign ChannelListViewModel
sure
i am using a channelListFragment where inside onCreateView i am assigning the viewModel
private ChannelListViewModel viewModel;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //....
viewModel = new ViewModelProvider(this).get(ChannelListViewModel.class);
FilterObject filter = Filters.INSTANCE.eq("type", "messaging");
viewModel.setQuery(filter,null);
//... }
it previously worked alright when i used the sdk version 4.0.13 after upgrading to 4.2.10 beta i am facing this issue
I am facing same problem with the channel activity as well with the message activity. there also i am facing problem with the view model
E/AndroidRuntime: FATAL EXCEPTION: main
Process: abentra.com, PID: 32514
java.lang.RuntimeException: Unable to start activity ComponentInfo{abentra.com/abentra.com.views.fragments.stream_chat.ChannelActivity}: kotlin.UninitializedPropertyAccessException: lateinit property instance has not been initialized
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property instance has not been initialized
at io.getstream.chat.android.livedata.ChatDomain$Companion.instance(ChatDomain.kt:140)
at io.getstream.chat.android.livedata.ChatDomain.instance(Unknown Source:2)
at com.getstream.sdk.chat.viewmodel.ChannelViewModel.
ChannelViewModelFactory factory = new ChannelViewModelFactory(getApplication(), channelType, channelId); viewModel = new ViewModelProvider(this, factory).get(ChannelViewModel.class);
this is how i am initialising
Initialisation of SDK is indeed has been changed since 4.0.13. It is still in beta and we're sorting out api, so breaking changes and bugs will appear.
You need to initialise ChatDomain to use viewmodels. You can see how it's done here:
https://github.com/elevenetc/stream-chat-android-tutorials/blob/57d8809bbc031716b0c32e2f042eb915977b0e37/java/app/src/main/java/com/example/chattutorial/ChannelListActivity.java#L48
And here is channel activity: https://github.com/elevenetc/stream-chat-android-tutorials/blob/master/java/app/src/main/java/com/example/chattutorial/ChannelActivity.java