Classifier does not have a companion object, and thus must be initialized here
Maybe this question is asked but not getting clue from the solutions which can be applied on my code.
The situation is:
I have an Activity where an interface is declared and I have a ViewModel
class which has override interface and want to invoke the method of interface from Activity
to make changes in ViewModel
class but unable to call method in Activity
saying ViewModel class does not have a companion object, and thus must be initialized here. How to resolve this?
var selection: setSelectionSubRow? = null
selection=RowSubTShirtViewModel
selection!!.setNameSelection(false)
above code is in Activity
whose name is TShirtActivity
.
below code is from RowViewModel
class
class RowSubTShirtViewModel(private val subTShirtAdapter: SubTShirtAdapter, val context: TShirtActivity,
val tShirtBean: CommonItemBean, private val parentPosition: Int, private val position: Int) : BaseObservable() ,TShirtActivity.setSelectionSubRow{
fun getImageDrawable(): Drawable {
return if (tShirtBean.isSelected)
ContextCompat.getDrawable(context, R.drawable.green_border_circle)!!
else
ContextCompat.getDrawable(context, R.drawable.border_circle)!!
}
override fun setNameSelection(selection: Boolean) {
if (parentPosition == 6) {
if (position == 1) {
tShirtBean.isSelected = false
}
}
}
android kotlin interface
add a comment |
Maybe this question is asked but not getting clue from the solutions which can be applied on my code.
The situation is:
I have an Activity where an interface is declared and I have a ViewModel
class which has override interface and want to invoke the method of interface from Activity
to make changes in ViewModel
class but unable to call method in Activity
saying ViewModel class does not have a companion object, and thus must be initialized here. How to resolve this?
var selection: setSelectionSubRow? = null
selection=RowSubTShirtViewModel
selection!!.setNameSelection(false)
above code is in Activity
whose name is TShirtActivity
.
below code is from RowViewModel
class
class RowSubTShirtViewModel(private val subTShirtAdapter: SubTShirtAdapter, val context: TShirtActivity,
val tShirtBean: CommonItemBean, private val parentPosition: Int, private val position: Int) : BaseObservable() ,TShirtActivity.setSelectionSubRow{
fun getImageDrawable(): Drawable {
return if (tShirtBean.isSelected)
ContextCompat.getDrawable(context, R.drawable.green_border_circle)!!
else
ContextCompat.getDrawable(context, R.drawable.border_circle)!!
}
override fun setNameSelection(selection: Boolean) {
if (parentPosition == 6) {
if (position == 1) {
tShirtBean.isSelected = false
}
}
}
android kotlin interface
add a comment |
Maybe this question is asked but not getting clue from the solutions which can be applied on my code.
The situation is:
I have an Activity where an interface is declared and I have a ViewModel
class which has override interface and want to invoke the method of interface from Activity
to make changes in ViewModel
class but unable to call method in Activity
saying ViewModel class does not have a companion object, and thus must be initialized here. How to resolve this?
var selection: setSelectionSubRow? = null
selection=RowSubTShirtViewModel
selection!!.setNameSelection(false)
above code is in Activity
whose name is TShirtActivity
.
below code is from RowViewModel
class
class RowSubTShirtViewModel(private val subTShirtAdapter: SubTShirtAdapter, val context: TShirtActivity,
val tShirtBean: CommonItemBean, private val parentPosition: Int, private val position: Int) : BaseObservable() ,TShirtActivity.setSelectionSubRow{
fun getImageDrawable(): Drawable {
return if (tShirtBean.isSelected)
ContextCompat.getDrawable(context, R.drawable.green_border_circle)!!
else
ContextCompat.getDrawable(context, R.drawable.border_circle)!!
}
override fun setNameSelection(selection: Boolean) {
if (parentPosition == 6) {
if (position == 1) {
tShirtBean.isSelected = false
}
}
}
android kotlin interface
Maybe this question is asked but not getting clue from the solutions which can be applied on my code.
The situation is:
I have an Activity where an interface is declared and I have a ViewModel
class which has override interface and want to invoke the method of interface from Activity
to make changes in ViewModel
class but unable to call method in Activity
saying ViewModel class does not have a companion object, and thus must be initialized here. How to resolve this?
var selection: setSelectionSubRow? = null
selection=RowSubTShirtViewModel
selection!!.setNameSelection(false)
above code is in Activity
whose name is TShirtActivity
.
below code is from RowViewModel
class
class RowSubTShirtViewModel(private val subTShirtAdapter: SubTShirtAdapter, val context: TShirtActivity,
val tShirtBean: CommonItemBean, private val parentPosition: Int, private val position: Int) : BaseObservable() ,TShirtActivity.setSelectionSubRow{
fun getImageDrawable(): Drawable {
return if (tShirtBean.isSelected)
ContextCompat.getDrawable(context, R.drawable.green_border_circle)!!
else
ContextCompat.getDrawable(context, R.drawable.border_circle)!!
}
override fun setNameSelection(selection: Boolean) {
if (parentPosition == 6) {
if (position == 1) {
tShirtBean.isSelected = false
}
}
}
android kotlin interface
android kotlin interface
edited Nov 26 '18 at 7:08
Farhana
asked Nov 26 '18 at 6:28
FarhanaFarhana
2,68552335
2,68552335
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
This line selection=RowSubTShirtViewModel
references the view model as if it were a named object, meaning you would have written instead of class object:
object RowSubTShirtViewModel {
//...
}
However, since that's not the case, kotlin is telling you that you cannot reference it like that and must initialize it. The conductor as quite a lot of parameters for me to guess what they are, but essentially you'd have to pass them in:
selection=RowSubTShirtViewModel(/*parameters here*/)
I got your point. but other problems have to face, Actually thisRowSubTShirtViewModel
is aviewmodel
ofsubAdapter
class and it is using inViewModel
class ofActivity
and there is adialog
inactivity
, indialog
on button click I want to reverse selection ofRecycleView
item and theRowSubTShirtViewModel
is aviewModel
for the adpater of thatrecyclerview
, so how can i manage constructor ofRowSubTShirtViewModel
inAcitivty
– Farhana
Nov 26 '18 at 7:29
1
That's just a classic dependency problem. You just carry on passing everything until you have all you need. For example, if you constructRowSubTShirtViewModel
in the adapter, which is used in an activity, then you can pass the activity as you instantiate the adapter and then pass it in as you instantiateRowSubTShirtViewModel
. There are other approaches using dependency injection frameworks like Dagger. I can't really tell you what suits you best, but the problem you're having will always lead to having to buildRowSubTShirtViewModel
.
– Fred
Nov 26 '18 at 9:09
Thanks Fred I will look both the solutions.
– Farhana
Nov 26 '18 at 9:11
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475759%2fclassifier-does-not-have-a-companion-object-and-thus-must-be-initialized-here%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This line selection=RowSubTShirtViewModel
references the view model as if it were a named object, meaning you would have written instead of class object:
object RowSubTShirtViewModel {
//...
}
However, since that's not the case, kotlin is telling you that you cannot reference it like that and must initialize it. The conductor as quite a lot of parameters for me to guess what they are, but essentially you'd have to pass them in:
selection=RowSubTShirtViewModel(/*parameters here*/)
I got your point. but other problems have to face, Actually thisRowSubTShirtViewModel
is aviewmodel
ofsubAdapter
class and it is using inViewModel
class ofActivity
and there is adialog
inactivity
, indialog
on button click I want to reverse selection ofRecycleView
item and theRowSubTShirtViewModel
is aviewModel
for the adpater of thatrecyclerview
, so how can i manage constructor ofRowSubTShirtViewModel
inAcitivty
– Farhana
Nov 26 '18 at 7:29
1
That's just a classic dependency problem. You just carry on passing everything until you have all you need. For example, if you constructRowSubTShirtViewModel
in the adapter, which is used in an activity, then you can pass the activity as you instantiate the adapter and then pass it in as you instantiateRowSubTShirtViewModel
. There are other approaches using dependency injection frameworks like Dagger. I can't really tell you what suits you best, but the problem you're having will always lead to having to buildRowSubTShirtViewModel
.
– Fred
Nov 26 '18 at 9:09
Thanks Fred I will look both the solutions.
– Farhana
Nov 26 '18 at 9:11
add a comment |
This line selection=RowSubTShirtViewModel
references the view model as if it were a named object, meaning you would have written instead of class object:
object RowSubTShirtViewModel {
//...
}
However, since that's not the case, kotlin is telling you that you cannot reference it like that and must initialize it. The conductor as quite a lot of parameters for me to guess what they are, but essentially you'd have to pass them in:
selection=RowSubTShirtViewModel(/*parameters here*/)
I got your point. but other problems have to face, Actually thisRowSubTShirtViewModel
is aviewmodel
ofsubAdapter
class and it is using inViewModel
class ofActivity
and there is adialog
inactivity
, indialog
on button click I want to reverse selection ofRecycleView
item and theRowSubTShirtViewModel
is aviewModel
for the adpater of thatrecyclerview
, so how can i manage constructor ofRowSubTShirtViewModel
inAcitivty
– Farhana
Nov 26 '18 at 7:29
1
That's just a classic dependency problem. You just carry on passing everything until you have all you need. For example, if you constructRowSubTShirtViewModel
in the adapter, which is used in an activity, then you can pass the activity as you instantiate the adapter and then pass it in as you instantiateRowSubTShirtViewModel
. There are other approaches using dependency injection frameworks like Dagger. I can't really tell you what suits you best, but the problem you're having will always lead to having to buildRowSubTShirtViewModel
.
– Fred
Nov 26 '18 at 9:09
Thanks Fred I will look both the solutions.
– Farhana
Nov 26 '18 at 9:11
add a comment |
This line selection=RowSubTShirtViewModel
references the view model as if it were a named object, meaning you would have written instead of class object:
object RowSubTShirtViewModel {
//...
}
However, since that's not the case, kotlin is telling you that you cannot reference it like that and must initialize it. The conductor as quite a lot of parameters for me to guess what they are, but essentially you'd have to pass them in:
selection=RowSubTShirtViewModel(/*parameters here*/)
This line selection=RowSubTShirtViewModel
references the view model as if it were a named object, meaning you would have written instead of class object:
object RowSubTShirtViewModel {
//...
}
However, since that's not the case, kotlin is telling you that you cannot reference it like that and must initialize it. The conductor as quite a lot of parameters for me to guess what they are, but essentially you'd have to pass them in:
selection=RowSubTShirtViewModel(/*parameters here*/)
answered Nov 26 '18 at 7:21
FredFred
8,79012645
8,79012645
I got your point. but other problems have to face, Actually thisRowSubTShirtViewModel
is aviewmodel
ofsubAdapter
class and it is using inViewModel
class ofActivity
and there is adialog
inactivity
, indialog
on button click I want to reverse selection ofRecycleView
item and theRowSubTShirtViewModel
is aviewModel
for the adpater of thatrecyclerview
, so how can i manage constructor ofRowSubTShirtViewModel
inAcitivty
– Farhana
Nov 26 '18 at 7:29
1
That's just a classic dependency problem. You just carry on passing everything until you have all you need. For example, if you constructRowSubTShirtViewModel
in the adapter, which is used in an activity, then you can pass the activity as you instantiate the adapter and then pass it in as you instantiateRowSubTShirtViewModel
. There are other approaches using dependency injection frameworks like Dagger. I can't really tell you what suits you best, but the problem you're having will always lead to having to buildRowSubTShirtViewModel
.
– Fred
Nov 26 '18 at 9:09
Thanks Fred I will look both the solutions.
– Farhana
Nov 26 '18 at 9:11
add a comment |
I got your point. but other problems have to face, Actually thisRowSubTShirtViewModel
is aviewmodel
ofsubAdapter
class and it is using inViewModel
class ofActivity
and there is adialog
inactivity
, indialog
on button click I want to reverse selection ofRecycleView
item and theRowSubTShirtViewModel
is aviewModel
for the adpater of thatrecyclerview
, so how can i manage constructor ofRowSubTShirtViewModel
inAcitivty
– Farhana
Nov 26 '18 at 7:29
1
That's just a classic dependency problem. You just carry on passing everything until you have all you need. For example, if you constructRowSubTShirtViewModel
in the adapter, which is used in an activity, then you can pass the activity as you instantiate the adapter and then pass it in as you instantiateRowSubTShirtViewModel
. There are other approaches using dependency injection frameworks like Dagger. I can't really tell you what suits you best, but the problem you're having will always lead to having to buildRowSubTShirtViewModel
.
– Fred
Nov 26 '18 at 9:09
Thanks Fred I will look both the solutions.
– Farhana
Nov 26 '18 at 9:11
I got your point. but other problems have to face, Actually this
RowSubTShirtViewModel
is a viewmodel
of subAdapter
class and it is using in ViewModel
class of Activity
and there is a dialog
in activity
, in dialog
on button click I want to reverse selection of RecycleView
item and the RowSubTShirtViewModel
is a viewModel
for the adpater of that recyclerview
, so how can i manage constructor of RowSubTShirtViewModel
in Acitivty
– Farhana
Nov 26 '18 at 7:29
I got your point. but other problems have to face, Actually this
RowSubTShirtViewModel
is a viewmodel
of subAdapter
class and it is using in ViewModel
class of Activity
and there is a dialog
in activity
, in dialog
on button click I want to reverse selection of RecycleView
item and the RowSubTShirtViewModel
is a viewModel
for the adpater of that recyclerview
, so how can i manage constructor of RowSubTShirtViewModel
in Acitivty
– Farhana
Nov 26 '18 at 7:29
1
1
That's just a classic dependency problem. You just carry on passing everything until you have all you need. For example, if you construct
RowSubTShirtViewModel
in the adapter, which is used in an activity, then you can pass the activity as you instantiate the adapter and then pass it in as you instantiate RowSubTShirtViewModel
. There are other approaches using dependency injection frameworks like Dagger. I can't really tell you what suits you best, but the problem you're having will always lead to having to build RowSubTShirtViewModel
.– Fred
Nov 26 '18 at 9:09
That's just a classic dependency problem. You just carry on passing everything until you have all you need. For example, if you construct
RowSubTShirtViewModel
in the adapter, which is used in an activity, then you can pass the activity as you instantiate the adapter and then pass it in as you instantiate RowSubTShirtViewModel
. There are other approaches using dependency injection frameworks like Dagger. I can't really tell you what suits you best, but the problem you're having will always lead to having to build RowSubTShirtViewModel
.– Fred
Nov 26 '18 at 9:09
Thanks Fred I will look both the solutions.
– Farhana
Nov 26 '18 at 9:11
Thanks Fred I will look both the solutions.
– Farhana
Nov 26 '18 at 9:11
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475759%2fclassifier-does-not-have-a-companion-object-and-thus-must-be-initialized-here%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown