error: incompatible types: HomeFragment cannot be converted to Context
I got an error on my Adapter
, this is my code, the error is pointed on this code, its on HomeFragment.java
, its says:
error: incompatible types: HomeFragment cannot be converted to Context
adapter = new Adapter(models,this);
here is my HomeFragment.java
public class HomeFragment extends Fragment {
//cardview
ViewPager viewPager;
Adapter adapter;
List<Model> models;
Integercolors = null;
ArgbEvaluator argbEvaluator = new ArgbEvaluator();
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_home,container,false);
//cardview
models = new ArrayList<>();
models.add(new Model(R.drawable.brochure,"Brochure","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.sticker,"Sticker","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.poster,"Poster","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.namecard,"Name Card","Lorem ipsum dolor sit amet"));
adapter = new Adapter(models,this);
viewPager = getView().findViewById(R.id.viewPager);
viewPager.setAdapter(adapter);
viewPager.setPadding(130,0,130,0);
}
}
Then here is my Adapter.java
public class Adapter extends PagerAdapter {
private List<Model> models;
private LayoutInflater layoutInflater;
private Context context;
public Adapter(List<Model> models, Context context) {
this.models = models;
this.context = context;
}
@Override
public int getCount() {
return models.size();
}
@Override
public boolean isViewFromObject(View view, @NonNull Object object) {
return view.equals(object);
}
@NonNull
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = LayoutInflater.from(context);
View view = layoutInflater.inflate(R.layout.item,container,false);
ImageView imageView;
TextView title,desc;
imageView = view.findViewById(R.id.image);
title = view.findViewById(R.id.title);
desc = view.findViewById(R.id.desc);
imageView.setImageResource(models.get(position).getImage());
title.setText(models.get(position).getTitle());
desc.setText(models.get(position).getDesc());
container.addView(view,0);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, @NonNull Object object) {
container.removeView((View)object);
}
}
java

add a comment |
I got an error on my Adapter
, this is my code, the error is pointed on this code, its on HomeFragment.java
, its says:
error: incompatible types: HomeFragment cannot be converted to Context
adapter = new Adapter(models,this);
here is my HomeFragment.java
public class HomeFragment extends Fragment {
//cardview
ViewPager viewPager;
Adapter adapter;
List<Model> models;
Integercolors = null;
ArgbEvaluator argbEvaluator = new ArgbEvaluator();
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_home,container,false);
//cardview
models = new ArrayList<>();
models.add(new Model(R.drawable.brochure,"Brochure","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.sticker,"Sticker","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.poster,"Poster","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.namecard,"Name Card","Lorem ipsum dolor sit amet"));
adapter = new Adapter(models,this);
viewPager = getView().findViewById(R.id.viewPager);
viewPager.setAdapter(adapter);
viewPager.setPadding(130,0,130,0);
}
}
Then here is my Adapter.java
public class Adapter extends PagerAdapter {
private List<Model> models;
private LayoutInflater layoutInflater;
private Context context;
public Adapter(List<Model> models, Context context) {
this.models = models;
this.context = context;
}
@Override
public int getCount() {
return models.size();
}
@Override
public boolean isViewFromObject(View view, @NonNull Object object) {
return view.equals(object);
}
@NonNull
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = LayoutInflater.from(context);
View view = layoutInflater.inflate(R.layout.item,container,false);
ImageView imageView;
TextView title,desc;
imageView = view.findViewById(R.id.image);
title = view.findViewById(R.id.title);
desc = view.findViewById(R.id.desc);
imageView.setImageResource(models.get(position).getImage());
title.setText(models.get(position).getTitle());
desc.setText(models.get(position).getDesc());
container.addView(view,0);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, @NonNull Object object) {
container.removeView((View)object);
}
}
java

add a comment |
I got an error on my Adapter
, this is my code, the error is pointed on this code, its on HomeFragment.java
, its says:
error: incompatible types: HomeFragment cannot be converted to Context
adapter = new Adapter(models,this);
here is my HomeFragment.java
public class HomeFragment extends Fragment {
//cardview
ViewPager viewPager;
Adapter adapter;
List<Model> models;
Integercolors = null;
ArgbEvaluator argbEvaluator = new ArgbEvaluator();
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_home,container,false);
//cardview
models = new ArrayList<>();
models.add(new Model(R.drawable.brochure,"Brochure","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.sticker,"Sticker","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.poster,"Poster","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.namecard,"Name Card","Lorem ipsum dolor sit amet"));
adapter = new Adapter(models,this);
viewPager = getView().findViewById(R.id.viewPager);
viewPager.setAdapter(adapter);
viewPager.setPadding(130,0,130,0);
}
}
Then here is my Adapter.java
public class Adapter extends PagerAdapter {
private List<Model> models;
private LayoutInflater layoutInflater;
private Context context;
public Adapter(List<Model> models, Context context) {
this.models = models;
this.context = context;
}
@Override
public int getCount() {
return models.size();
}
@Override
public boolean isViewFromObject(View view, @NonNull Object object) {
return view.equals(object);
}
@NonNull
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = LayoutInflater.from(context);
View view = layoutInflater.inflate(R.layout.item,container,false);
ImageView imageView;
TextView title,desc;
imageView = view.findViewById(R.id.image);
title = view.findViewById(R.id.title);
desc = view.findViewById(R.id.desc);
imageView.setImageResource(models.get(position).getImage());
title.setText(models.get(position).getTitle());
desc.setText(models.get(position).getDesc());
container.addView(view,0);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, @NonNull Object object) {
container.removeView((View)object);
}
}
java

I got an error on my Adapter
, this is my code, the error is pointed on this code, its on HomeFragment.java
, its says:
error: incompatible types: HomeFragment cannot be converted to Context
adapter = new Adapter(models,this);
here is my HomeFragment.java
public class HomeFragment extends Fragment {
//cardview
ViewPager viewPager;
Adapter adapter;
List<Model> models;
Integercolors = null;
ArgbEvaluator argbEvaluator = new ArgbEvaluator();
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_home,container,false);
//cardview
models = new ArrayList<>();
models.add(new Model(R.drawable.brochure,"Brochure","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.sticker,"Sticker","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.poster,"Poster","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.namecard,"Name Card","Lorem ipsum dolor sit amet"));
adapter = new Adapter(models,this);
viewPager = getView().findViewById(R.id.viewPager);
viewPager.setAdapter(adapter);
viewPager.setPadding(130,0,130,0);
}
}
Then here is my Adapter.java
public class Adapter extends PagerAdapter {
private List<Model> models;
private LayoutInflater layoutInflater;
private Context context;
public Adapter(List<Model> models, Context context) {
this.models = models;
this.context = context;
}
@Override
public int getCount() {
return models.size();
}
@Override
public boolean isViewFromObject(View view, @NonNull Object object) {
return view.equals(object);
}
@NonNull
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = LayoutInflater.from(context);
View view = layoutInflater.inflate(R.layout.item,container,false);
ImageView imageView;
TextView title,desc;
imageView = view.findViewById(R.id.image);
title = view.findViewById(R.id.title);
desc = view.findViewById(R.id.desc);
imageView.setImageResource(models.get(position).getImage());
title.setText(models.get(position).getTitle());
desc.setText(models.get(position).getDesc());
container.addView(view,0);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, @NonNull Object object) {
container.removeView((View)object);
}
}
java

java

edited Jan 2 at 8:30


Zlytherin
1,9023829
1,9023829
asked Jan 2 at 7:45
Bram WiratmaBram Wiratma
152
152
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Change this:
adapter = new Adapter(models,this);
to this:
adapter = new Adapter(models, (Context) getActivity());
You've to pass Context
. And a Activity
is cast-able to Context
but a Fragment
is not.
So, you've to retrieve a instance of current Activity
, which we are doing by getActivity()
.
If you want to create instance of Adapter
in a Activity
, then you can do that by simple passing this
, like I said before, a Activity
is cast-able to Context
but a Fragment
is not. So Activity
will be casted to Context
, but when you want to create the same in a Fragment
then you cannot simply pass this
, thus, it raised an error.
As you said in comment, now there is another error, That is because you are already return
ed something on the first line of that method, so, every line under that will never be reached, that is why there is that error, place this line
return inflater.inflate(R.layout.fragment_home,container,false);
at the end and error will be gone.
After some more editing in your method, your OnCreateView
will look something like this:
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_home, container, false); // Created a instance of View which we can return later.
//cardview
models = new ArrayList<>();
models.add(new Model(R.drawable.brochure,"Brochure","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.sticker,"Sticker","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.poster,"Poster","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.namecard,"Name Card","Lorem ipsum dolor sit amet"));
adapter = new Adapter(models,this);
viewPager = view.findViewById(R.id.viewPager); // Change getView() to view here.
viewPager.setAdapter(adapter);
viewPager.setPadding(130,0,130,0);
return view; // Returned the view.
}
thanks, the error is gone, but there is a new error its say "error: unreachable statement" on "models = new ArrayList<>();"
– Bram Wiratma
Jan 2 at 8:00
Which line i have to delete ?
– Bram Wiratma
Jan 2 at 8:09
@user3291362 I've edited it, reload page and check my answer now
– Zlytherin
Jan 2 at 8:12
Dammmnn the error is gone man, thanks, youre superb :D, but why when i run this code, the application is force close, then i saw the log there is an error on "viewPager = getView().findViewById(R.id.viewPager);"
– Bram Wiratma
Jan 2 at 8:21
1
MANY THANKSS MANNN!! YOU SAVE MY LIFE, you da real MVP! Thanks!
– Bram Wiratma
Jan 2 at 8:31
|
show 1 more comment
In place of this
, use getActivity()
Change this
adapter = new Adapter(models,this);
to
adapter = new Adapter(models,getActivity());
thanks, the error is gone, but there is a new error its say "error: unreachable statement" on "models = new ArrayList<>();"
– Bram Wiratma
Jan 2 at 7:55
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%2f54002865%2ferror-incompatible-types-homefragment-cannot-be-converted-to-context%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Change this:
adapter = new Adapter(models,this);
to this:
adapter = new Adapter(models, (Context) getActivity());
You've to pass Context
. And a Activity
is cast-able to Context
but a Fragment
is not.
So, you've to retrieve a instance of current Activity
, which we are doing by getActivity()
.
If you want to create instance of Adapter
in a Activity
, then you can do that by simple passing this
, like I said before, a Activity
is cast-able to Context
but a Fragment
is not. So Activity
will be casted to Context
, but when you want to create the same in a Fragment
then you cannot simply pass this
, thus, it raised an error.
As you said in comment, now there is another error, That is because you are already return
ed something on the first line of that method, so, every line under that will never be reached, that is why there is that error, place this line
return inflater.inflate(R.layout.fragment_home,container,false);
at the end and error will be gone.
After some more editing in your method, your OnCreateView
will look something like this:
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_home, container, false); // Created a instance of View which we can return later.
//cardview
models = new ArrayList<>();
models.add(new Model(R.drawable.brochure,"Brochure","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.sticker,"Sticker","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.poster,"Poster","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.namecard,"Name Card","Lorem ipsum dolor sit amet"));
adapter = new Adapter(models,this);
viewPager = view.findViewById(R.id.viewPager); // Change getView() to view here.
viewPager.setAdapter(adapter);
viewPager.setPadding(130,0,130,0);
return view; // Returned the view.
}
thanks, the error is gone, but there is a new error its say "error: unreachable statement" on "models = new ArrayList<>();"
– Bram Wiratma
Jan 2 at 8:00
Which line i have to delete ?
– Bram Wiratma
Jan 2 at 8:09
@user3291362 I've edited it, reload page and check my answer now
– Zlytherin
Jan 2 at 8:12
Dammmnn the error is gone man, thanks, youre superb :D, but why when i run this code, the application is force close, then i saw the log there is an error on "viewPager = getView().findViewById(R.id.viewPager);"
– Bram Wiratma
Jan 2 at 8:21
1
MANY THANKSS MANNN!! YOU SAVE MY LIFE, you da real MVP! Thanks!
– Bram Wiratma
Jan 2 at 8:31
|
show 1 more comment
Change this:
adapter = new Adapter(models,this);
to this:
adapter = new Adapter(models, (Context) getActivity());
You've to pass Context
. And a Activity
is cast-able to Context
but a Fragment
is not.
So, you've to retrieve a instance of current Activity
, which we are doing by getActivity()
.
If you want to create instance of Adapter
in a Activity
, then you can do that by simple passing this
, like I said before, a Activity
is cast-able to Context
but a Fragment
is not. So Activity
will be casted to Context
, but when you want to create the same in a Fragment
then you cannot simply pass this
, thus, it raised an error.
As you said in comment, now there is another error, That is because you are already return
ed something on the first line of that method, so, every line under that will never be reached, that is why there is that error, place this line
return inflater.inflate(R.layout.fragment_home,container,false);
at the end and error will be gone.
After some more editing in your method, your OnCreateView
will look something like this:
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_home, container, false); // Created a instance of View which we can return later.
//cardview
models = new ArrayList<>();
models.add(new Model(R.drawable.brochure,"Brochure","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.sticker,"Sticker","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.poster,"Poster","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.namecard,"Name Card","Lorem ipsum dolor sit amet"));
adapter = new Adapter(models,this);
viewPager = view.findViewById(R.id.viewPager); // Change getView() to view here.
viewPager.setAdapter(adapter);
viewPager.setPadding(130,0,130,0);
return view; // Returned the view.
}
thanks, the error is gone, but there is a new error its say "error: unreachable statement" on "models = new ArrayList<>();"
– Bram Wiratma
Jan 2 at 8:00
Which line i have to delete ?
– Bram Wiratma
Jan 2 at 8:09
@user3291362 I've edited it, reload page and check my answer now
– Zlytherin
Jan 2 at 8:12
Dammmnn the error is gone man, thanks, youre superb :D, but why when i run this code, the application is force close, then i saw the log there is an error on "viewPager = getView().findViewById(R.id.viewPager);"
– Bram Wiratma
Jan 2 at 8:21
1
MANY THANKSS MANNN!! YOU SAVE MY LIFE, you da real MVP! Thanks!
– Bram Wiratma
Jan 2 at 8:31
|
show 1 more comment
Change this:
adapter = new Adapter(models,this);
to this:
adapter = new Adapter(models, (Context) getActivity());
You've to pass Context
. And a Activity
is cast-able to Context
but a Fragment
is not.
So, you've to retrieve a instance of current Activity
, which we are doing by getActivity()
.
If you want to create instance of Adapter
in a Activity
, then you can do that by simple passing this
, like I said before, a Activity
is cast-able to Context
but a Fragment
is not. So Activity
will be casted to Context
, but when you want to create the same in a Fragment
then you cannot simply pass this
, thus, it raised an error.
As you said in comment, now there is another error, That is because you are already return
ed something on the first line of that method, so, every line under that will never be reached, that is why there is that error, place this line
return inflater.inflate(R.layout.fragment_home,container,false);
at the end and error will be gone.
After some more editing in your method, your OnCreateView
will look something like this:
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_home, container, false); // Created a instance of View which we can return later.
//cardview
models = new ArrayList<>();
models.add(new Model(R.drawable.brochure,"Brochure","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.sticker,"Sticker","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.poster,"Poster","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.namecard,"Name Card","Lorem ipsum dolor sit amet"));
adapter = new Adapter(models,this);
viewPager = view.findViewById(R.id.viewPager); // Change getView() to view here.
viewPager.setAdapter(adapter);
viewPager.setPadding(130,0,130,0);
return view; // Returned the view.
}
Change this:
adapter = new Adapter(models,this);
to this:
adapter = new Adapter(models, (Context) getActivity());
You've to pass Context
. And a Activity
is cast-able to Context
but a Fragment
is not.
So, you've to retrieve a instance of current Activity
, which we are doing by getActivity()
.
If you want to create instance of Adapter
in a Activity
, then you can do that by simple passing this
, like I said before, a Activity
is cast-able to Context
but a Fragment
is not. So Activity
will be casted to Context
, but when you want to create the same in a Fragment
then you cannot simply pass this
, thus, it raised an error.
As you said in comment, now there is another error, That is because you are already return
ed something on the first line of that method, so, every line under that will never be reached, that is why there is that error, place this line
return inflater.inflate(R.layout.fragment_home,container,false);
at the end and error will be gone.
After some more editing in your method, your OnCreateView
will look something like this:
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_home, container, false); // Created a instance of View which we can return later.
//cardview
models = new ArrayList<>();
models.add(new Model(R.drawable.brochure,"Brochure","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.sticker,"Sticker","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.poster,"Poster","Lorem ipsum dolor sit amet"));
models.add(new Model(R.drawable.namecard,"Name Card","Lorem ipsum dolor sit amet"));
adapter = new Adapter(models,this);
viewPager = view.findViewById(R.id.viewPager); // Change getView() to view here.
viewPager.setAdapter(adapter);
viewPager.setPadding(130,0,130,0);
return view; // Returned the view.
}
edited Jan 2 at 8:25
answered Jan 2 at 7:50


ZlytherinZlytherin
1,9023829
1,9023829
thanks, the error is gone, but there is a new error its say "error: unreachable statement" on "models = new ArrayList<>();"
– Bram Wiratma
Jan 2 at 8:00
Which line i have to delete ?
– Bram Wiratma
Jan 2 at 8:09
@user3291362 I've edited it, reload page and check my answer now
– Zlytherin
Jan 2 at 8:12
Dammmnn the error is gone man, thanks, youre superb :D, but why when i run this code, the application is force close, then i saw the log there is an error on "viewPager = getView().findViewById(R.id.viewPager);"
– Bram Wiratma
Jan 2 at 8:21
1
MANY THANKSS MANNN!! YOU SAVE MY LIFE, you da real MVP! Thanks!
– Bram Wiratma
Jan 2 at 8:31
|
show 1 more comment
thanks, the error is gone, but there is a new error its say "error: unreachable statement" on "models = new ArrayList<>();"
– Bram Wiratma
Jan 2 at 8:00
Which line i have to delete ?
– Bram Wiratma
Jan 2 at 8:09
@user3291362 I've edited it, reload page and check my answer now
– Zlytherin
Jan 2 at 8:12
Dammmnn the error is gone man, thanks, youre superb :D, but why when i run this code, the application is force close, then i saw the log there is an error on "viewPager = getView().findViewById(R.id.viewPager);"
– Bram Wiratma
Jan 2 at 8:21
1
MANY THANKSS MANNN!! YOU SAVE MY LIFE, you da real MVP! Thanks!
– Bram Wiratma
Jan 2 at 8:31
thanks, the error is gone, but there is a new error its say "error: unreachable statement" on "models = new ArrayList<>();"
– Bram Wiratma
Jan 2 at 8:00
thanks, the error is gone, but there is a new error its say "error: unreachable statement" on "models = new ArrayList<>();"
– Bram Wiratma
Jan 2 at 8:00
Which line i have to delete ?
– Bram Wiratma
Jan 2 at 8:09
Which line i have to delete ?
– Bram Wiratma
Jan 2 at 8:09
@user3291362 I've edited it, reload page and check my answer now
– Zlytherin
Jan 2 at 8:12
@user3291362 I've edited it, reload page and check my answer now
– Zlytherin
Jan 2 at 8:12
Dammmnn the error is gone man, thanks, youre superb :D, but why when i run this code, the application is force close, then i saw the log there is an error on "viewPager = getView().findViewById(R.id.viewPager);"
– Bram Wiratma
Jan 2 at 8:21
Dammmnn the error is gone man, thanks, youre superb :D, but why when i run this code, the application is force close, then i saw the log there is an error on "viewPager = getView().findViewById(R.id.viewPager);"
– Bram Wiratma
Jan 2 at 8:21
1
1
MANY THANKSS MANNN!! YOU SAVE MY LIFE, you da real MVP! Thanks!
– Bram Wiratma
Jan 2 at 8:31
MANY THANKSS MANNN!! YOU SAVE MY LIFE, you da real MVP! Thanks!
– Bram Wiratma
Jan 2 at 8:31
|
show 1 more comment
In place of this
, use getActivity()
Change this
adapter = new Adapter(models,this);
to
adapter = new Adapter(models,getActivity());
thanks, the error is gone, but there is a new error its say "error: unreachable statement" on "models = new ArrayList<>();"
– Bram Wiratma
Jan 2 at 7:55
add a comment |
In place of this
, use getActivity()
Change this
adapter = new Adapter(models,this);
to
adapter = new Adapter(models,getActivity());
thanks, the error is gone, but there is a new error its say "error: unreachable statement" on "models = new ArrayList<>();"
– Bram Wiratma
Jan 2 at 7:55
add a comment |
In place of this
, use getActivity()
Change this
adapter = new Adapter(models,this);
to
adapter = new Adapter(models,getActivity());
In place of this
, use getActivity()
Change this
adapter = new Adapter(models,this);
to
adapter = new Adapter(models,getActivity());
answered Jan 2 at 7:50


okcomputer_kidokcomputer_kid
33839
33839
thanks, the error is gone, but there is a new error its say "error: unreachable statement" on "models = new ArrayList<>();"
– Bram Wiratma
Jan 2 at 7:55
add a comment |
thanks, the error is gone, but there is a new error its say "error: unreachable statement" on "models = new ArrayList<>();"
– Bram Wiratma
Jan 2 at 7:55
thanks, the error is gone, but there is a new error its say "error: unreachable statement" on "models = new ArrayList<>();"
– Bram Wiratma
Jan 2 at 7:55
thanks, the error is gone, but there is a new error its say "error: unreachable statement" on "models = new ArrayList<>();"
– Bram Wiratma
Jan 2 at 7:55
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%2f54002865%2ferror-incompatible-types-homefragment-cannot-be-converted-to-context%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