CardView binded to worker class returns null
I Have the followin CardView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinatorLayout">
<fragment
android:id="@+id/mapActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Map.MyMap" />
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:visibility="gone"
android:id="@+id/cardViewData"
android:backgroundTint="@color/colorPrimary"
app:cardCornerRadius="8dp">
...
Now, I call this CardView in my Activity the this way to get the id of it and pass that CardView to a worker class to handle some logic there with it (I just need to set it visible )
private CardView mCardViewData;
inside onCreate() , after setContentView
mCardViewData = findViewById(R.id.cardViewData);
new MapsUtils(this,mCardViewData);
As you can see , Im sending this cardview to the worker class where I get it as follow
private CardView mCardViewData;
public MapsUtils(Context context,CardView cardView{
this.mCardViewData = cardView;
this.mContext = context;
}
And then Im using it inside MapsUtil in a method like this
private void initRun(){
mCardViewData.setVisibility(View.VISIBLE);
}
I need to have this cardview binded to my worker class because I manage the logic of the map in a worker class and not in the view.
Now, what I'm getting is this
java.lang.NullPointerException: Attempt to invoke virtual method
'void androidx.cardview.widget.CardView.setVisibility(int)' on a null
object reference
at com.utils.MapsUtils.initRun(MapsUtils.java:182)
at com.utils.MapsUtils.access$000(MapsUtils.java:62)
at com.utils.MapsUtils$2.onClick(MapsUtils.java:219)
Error points here
mCardViewData.setVisibility(View.VISIBLE);
And Im trying to see where Im wrong because I just defined all I need to work with that CardView in my worker class
java android cardview
|
show 3 more comments
I Have the followin CardView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinatorLayout">
<fragment
android:id="@+id/mapActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Map.MyMap" />
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:visibility="gone"
android:id="@+id/cardViewData"
android:backgroundTint="@color/colorPrimary"
app:cardCornerRadius="8dp">
...
Now, I call this CardView in my Activity the this way to get the id of it and pass that CardView to a worker class to handle some logic there with it (I just need to set it visible )
private CardView mCardViewData;
inside onCreate() , after setContentView
mCardViewData = findViewById(R.id.cardViewData);
new MapsUtils(this,mCardViewData);
As you can see , Im sending this cardview to the worker class where I get it as follow
private CardView mCardViewData;
public MapsUtils(Context context,CardView cardView{
this.mCardViewData = cardView;
this.mContext = context;
}
And then Im using it inside MapsUtil in a method like this
private void initRun(){
mCardViewData.setVisibility(View.VISIBLE);
}
I need to have this cardview binded to my worker class because I manage the logic of the map in a worker class and not in the view.
Now, what I'm getting is this
java.lang.NullPointerException: Attempt to invoke virtual method
'void androidx.cardview.widget.CardView.setVisibility(int)' on a null
object reference
at com.utils.MapsUtils.initRun(MapsUtils.java:182)
at com.utils.MapsUtils.access$000(MapsUtils.java:62)
at com.utils.MapsUtils$2.onClick(MapsUtils.java:219)
Error points here
mCardViewData.setVisibility(View.VISIBLE);
And Im trying to see where Im wrong because I just defined all I need to work with that CardView in my worker class
java android cardview
i think so you should addandroid.support.v7.widget.CardView
instead ofandroidx.cardview.widget.CardView
in XML
– Ali Ahmed
Nov 23 '18 at 12:48
I'm using androidx libraries, it works the same
– Todd
Nov 23 '18 at 12:49
make sure you're calinginitRun()
after initializingCardView
. error says yourCardView
is not initialized , so its NULL
– Ali Ahmed
Nov 23 '18 at 12:51
hmm let me see.
– Todd
Nov 23 '18 at 12:52
yes, Im initializing it after that
– Todd
Nov 23 '18 at 12:52
|
show 3 more comments
I Have the followin CardView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinatorLayout">
<fragment
android:id="@+id/mapActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Map.MyMap" />
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:visibility="gone"
android:id="@+id/cardViewData"
android:backgroundTint="@color/colorPrimary"
app:cardCornerRadius="8dp">
...
Now, I call this CardView in my Activity the this way to get the id of it and pass that CardView to a worker class to handle some logic there with it (I just need to set it visible )
private CardView mCardViewData;
inside onCreate() , after setContentView
mCardViewData = findViewById(R.id.cardViewData);
new MapsUtils(this,mCardViewData);
As you can see , Im sending this cardview to the worker class where I get it as follow
private CardView mCardViewData;
public MapsUtils(Context context,CardView cardView{
this.mCardViewData = cardView;
this.mContext = context;
}
And then Im using it inside MapsUtil in a method like this
private void initRun(){
mCardViewData.setVisibility(View.VISIBLE);
}
I need to have this cardview binded to my worker class because I manage the logic of the map in a worker class and not in the view.
Now, what I'm getting is this
java.lang.NullPointerException: Attempt to invoke virtual method
'void androidx.cardview.widget.CardView.setVisibility(int)' on a null
object reference
at com.utils.MapsUtils.initRun(MapsUtils.java:182)
at com.utils.MapsUtils.access$000(MapsUtils.java:62)
at com.utils.MapsUtils$2.onClick(MapsUtils.java:219)
Error points here
mCardViewData.setVisibility(View.VISIBLE);
And Im trying to see where Im wrong because I just defined all I need to work with that CardView in my worker class
java android cardview
I Have the followin CardView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinatorLayout">
<fragment
android:id="@+id/mapActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Map.MyMap" />
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:visibility="gone"
android:id="@+id/cardViewData"
android:backgroundTint="@color/colorPrimary"
app:cardCornerRadius="8dp">
...
Now, I call this CardView in my Activity the this way to get the id of it and pass that CardView to a worker class to handle some logic there with it (I just need to set it visible )
private CardView mCardViewData;
inside onCreate() , after setContentView
mCardViewData = findViewById(R.id.cardViewData);
new MapsUtils(this,mCardViewData);
As you can see , Im sending this cardview to the worker class where I get it as follow
private CardView mCardViewData;
public MapsUtils(Context context,CardView cardView{
this.mCardViewData = cardView;
this.mContext = context;
}
And then Im using it inside MapsUtil in a method like this
private void initRun(){
mCardViewData.setVisibility(View.VISIBLE);
}
I need to have this cardview binded to my worker class because I manage the logic of the map in a worker class and not in the view.
Now, what I'm getting is this
java.lang.NullPointerException: Attempt to invoke virtual method
'void androidx.cardview.widget.CardView.setVisibility(int)' on a null
object reference
at com.utils.MapsUtils.initRun(MapsUtils.java:182)
at com.utils.MapsUtils.access$000(MapsUtils.java:62)
at com.utils.MapsUtils$2.onClick(MapsUtils.java:219)
Error points here
mCardViewData.setVisibility(View.VISIBLE);
And Im trying to see where Im wrong because I just defined all I need to work with that CardView in my worker class
java android cardview
java android cardview
asked Nov 23 '18 at 12:40
ToddTodd
10412
10412
i think so you should addandroid.support.v7.widget.CardView
instead ofandroidx.cardview.widget.CardView
in XML
– Ali Ahmed
Nov 23 '18 at 12:48
I'm using androidx libraries, it works the same
– Todd
Nov 23 '18 at 12:49
make sure you're calinginitRun()
after initializingCardView
. error says yourCardView
is not initialized , so its NULL
– Ali Ahmed
Nov 23 '18 at 12:51
hmm let me see.
– Todd
Nov 23 '18 at 12:52
yes, Im initializing it after that
– Todd
Nov 23 '18 at 12:52
|
show 3 more comments
i think so you should addandroid.support.v7.widget.CardView
instead ofandroidx.cardview.widget.CardView
in XML
– Ali Ahmed
Nov 23 '18 at 12:48
I'm using androidx libraries, it works the same
– Todd
Nov 23 '18 at 12:49
make sure you're calinginitRun()
after initializingCardView
. error says yourCardView
is not initialized , so its NULL
– Ali Ahmed
Nov 23 '18 at 12:51
hmm let me see.
– Todd
Nov 23 '18 at 12:52
yes, Im initializing it after that
– Todd
Nov 23 '18 at 12:52
i think so you should add
android.support.v7.widget.CardView
instead of androidx.cardview.widget.CardView
in XML– Ali Ahmed
Nov 23 '18 at 12:48
i think so you should add
android.support.v7.widget.CardView
instead of androidx.cardview.widget.CardView
in XML– Ali Ahmed
Nov 23 '18 at 12:48
I'm using androidx libraries, it works the same
– Todd
Nov 23 '18 at 12:49
I'm using androidx libraries, it works the same
– Todd
Nov 23 '18 at 12:49
make sure you're caling
initRun()
after initializing CardView
. error says your CardView
is not initialized , so its NULL– Ali Ahmed
Nov 23 '18 at 12:51
make sure you're caling
initRun()
after initializing CardView
. error says your CardView
is not initialized , so its NULL– Ali Ahmed
Nov 23 '18 at 12:51
hmm let me see.
– Todd
Nov 23 '18 at 12:52
hmm let me see.
– Todd
Nov 23 '18 at 12:52
yes, Im initializing it after that
– Todd
Nov 23 '18 at 12:52
yes, Im initializing it after that
– Todd
Nov 23 '18 at 12:52
|
show 3 more comments
1 Answer
1
active
oldest
votes
Ok, I found the problem, the problem was that since Im using multiple constructors, the constructor that init a method that calls for the CardView was initializing it without all the elements I needed, now I binded all my elements to that constructor and its working
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%2f53446908%2fcardview-binded-to-worker-class-returns-null%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
Ok, I found the problem, the problem was that since Im using multiple constructors, the constructor that init a method that calls for the CardView was initializing it without all the elements I needed, now I binded all my elements to that constructor and its working
add a comment |
Ok, I found the problem, the problem was that since Im using multiple constructors, the constructor that init a method that calls for the CardView was initializing it without all the elements I needed, now I binded all my elements to that constructor and its working
add a comment |
Ok, I found the problem, the problem was that since Im using multiple constructors, the constructor that init a method that calls for the CardView was initializing it without all the elements I needed, now I binded all my elements to that constructor and its working
Ok, I found the problem, the problem was that since Im using multiple constructors, the constructor that init a method that calls for the CardView was initializing it without all the elements I needed, now I binded all my elements to that constructor and its working
answered Nov 23 '18 at 12:56
ToddTodd
10412
10412
add a comment |
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%2f53446908%2fcardview-binded-to-worker-class-returns-null%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
i think so you should add
android.support.v7.widget.CardView
instead ofandroidx.cardview.widget.CardView
in XML– Ali Ahmed
Nov 23 '18 at 12:48
I'm using androidx libraries, it works the same
– Todd
Nov 23 '18 at 12:49
make sure you're caling
initRun()
after initializingCardView
. error says yourCardView
is not initialized , so its NULL– Ali Ahmed
Nov 23 '18 at 12:51
hmm let me see.
– Todd
Nov 23 '18 at 12:52
yes, Im initializing it after that
– Todd
Nov 23 '18 at 12:52