D/Volley: [1] 5.onErrorResponse: Product
up vote
0
down vote
favorite
How do I insert data from MySQL into Gridview on Fragments? I've tried it with a coding method used for Activity. I've changed a lot but it's still wrong. This is my coding:
/**
* A simple @link Fragment subclass.
*/
public class Product extends Fragment implements
SwipeRefreshLayout.OnRefreshListener
GridView grid_product;
SwipeRefreshLayout swipe;
List<ProductData> newsList = new ArrayList<ProductData>();
private static final String TAG = Product.class.getSimpleName();
private static String url_list = Server.URL + "news.php?offset=";
private int offSet = 0;
int no;
ProductAdapter adapter;
public static final String TAG_NO = "no";
public static final String TAG_ID = "id";
public static final String TAG_JUDUL = "judul";
public static final String TAG_TGL = "tgl";
public static final String TAG_ISI = "isi";
public static final String TAG_GAMBAR = "gambar";
Handler handler;
Runnable runnable;
public Product()
// Required empty public constructor
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_product, container, false);
swipe = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
grid_product = (GridView) view.findViewById(R.id.grid_product);
setProduct();
return view;
private void setProduct()
adapter = new ProductAdapter(getActivity(), newsList);
grid_product.setAdapter(adapter);
grid_product.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
//pindah activity
startActivity(new Intent(
getActivity(), DetailActivity.class
));
);
I don't know where the mistake is:
swipe.setOnRefreshListener(this);
swipe.post(new Runnable()
@Override
public void run()
swipe.setRefreshing(true);
newsList.clear();
adapter.notifyDataSetChanged();
callNews(0);
);
grid_product.setOnScrollListener(new AbsListView.OnScrollListener()
private int currentVisibleItemCount;
private int currentScrollState;
private int currentFirstVisibleItem;
private int totalItem;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState)
this.currentScrollState = scrollState;
this.isScrollCompleted();
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
this.currentFirstVisibleItem = firstVisibleItem;
this.currentVisibleItemCount = visibleItemCount;
this.totalItem = totalItemCount;
private void isScrollCompleted()
if (totalItem - currentFirstVisibleItem == currentVisibleItemCount
&& this.currentScrollState == SCROLL_STATE_IDLE)
swipe.setRefreshing(true);
handler = new Handler();
runnable = new Runnable()
public void run()
callNews(offSet);
;
handler.postDelayed(runnable, 3000);
);
@Override
public void onRefresh()
newsList.clear();
adapter.notifyDataSetChanged();
callNews(0);
I don't know where the mistake is:
private void callNews(int page)
swipe.setRefreshing(true);
// Creating volley request obj
JsonArrayRequest arrReq = new JsonArrayRequest(url_list + page,
new Response.Listener<JSONArray>()
@Override
public void onResponse(JSONArray response)
Log.d(TAG, response.toString());
if (response.length() > 0)
// Parsing json
for (int i = 0; i < response.length(); i++)
try
JSONObject obj = response.getJSONObject(i);
ProductData news = new ProductData();
no = obj.getInt(TAG_NO);
news.addId(obj.getString(TAG_ID));
news.addJudul(obj.getString(TAG_JUDUL));
if (obj.getString(TAG_GAMBAR) != "")
news.addGambar(obj.getString(TAG_GAMBAR));
news.addDatetime(obj.getString(TAG_TGL));
news.addIsi(obj.getString(TAG_ISI));
// adding news to news array
newsList.add(news);
if (no > offSet)
offSet = no;
Log.d(TAG, "offSet " + offSet);
catch (JSONException e)
Log.e(TAG, "JSON Parsing error: " + e.getMessage());
// notifying list adapter about data changes
// so that it renders the list view with updated data
adapter.notifyDataSetChanged();
swipe.setRefreshing(false);
, new Response.ErrorListener()
@Override
public void onErrorResponse(VolleyError error)
VolleyLog.d(TAG, "Error: " + error.getMessage());
swipe.setRefreshing(false);
);
// Adding request to request queue
AppController.getInstance().addToRequestQueue(arrReq);
json android-volley
New contributor
add a comment |
up vote
0
down vote
favorite
How do I insert data from MySQL into Gridview on Fragments? I've tried it with a coding method used for Activity. I've changed a lot but it's still wrong. This is my coding:
/**
* A simple @link Fragment subclass.
*/
public class Product extends Fragment implements
SwipeRefreshLayout.OnRefreshListener
GridView grid_product;
SwipeRefreshLayout swipe;
List<ProductData> newsList = new ArrayList<ProductData>();
private static final String TAG = Product.class.getSimpleName();
private static String url_list = Server.URL + "news.php?offset=";
private int offSet = 0;
int no;
ProductAdapter adapter;
public static final String TAG_NO = "no";
public static final String TAG_ID = "id";
public static final String TAG_JUDUL = "judul";
public static final String TAG_TGL = "tgl";
public static final String TAG_ISI = "isi";
public static final String TAG_GAMBAR = "gambar";
Handler handler;
Runnable runnable;
public Product()
// Required empty public constructor
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_product, container, false);
swipe = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
grid_product = (GridView) view.findViewById(R.id.grid_product);
setProduct();
return view;
private void setProduct()
adapter = new ProductAdapter(getActivity(), newsList);
grid_product.setAdapter(adapter);
grid_product.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
//pindah activity
startActivity(new Intent(
getActivity(), DetailActivity.class
));
);
I don't know where the mistake is:
swipe.setOnRefreshListener(this);
swipe.post(new Runnable()
@Override
public void run()
swipe.setRefreshing(true);
newsList.clear();
adapter.notifyDataSetChanged();
callNews(0);
);
grid_product.setOnScrollListener(new AbsListView.OnScrollListener()
private int currentVisibleItemCount;
private int currentScrollState;
private int currentFirstVisibleItem;
private int totalItem;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState)
this.currentScrollState = scrollState;
this.isScrollCompleted();
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
this.currentFirstVisibleItem = firstVisibleItem;
this.currentVisibleItemCount = visibleItemCount;
this.totalItem = totalItemCount;
private void isScrollCompleted()
if (totalItem - currentFirstVisibleItem == currentVisibleItemCount
&& this.currentScrollState == SCROLL_STATE_IDLE)
swipe.setRefreshing(true);
handler = new Handler();
runnable = new Runnable()
public void run()
callNews(offSet);
;
handler.postDelayed(runnable, 3000);
);
@Override
public void onRefresh()
newsList.clear();
adapter.notifyDataSetChanged();
callNews(0);
I don't know where the mistake is:
private void callNews(int page)
swipe.setRefreshing(true);
// Creating volley request obj
JsonArrayRequest arrReq = new JsonArrayRequest(url_list + page,
new Response.Listener<JSONArray>()
@Override
public void onResponse(JSONArray response)
Log.d(TAG, response.toString());
if (response.length() > 0)
// Parsing json
for (int i = 0; i < response.length(); i++)
try
JSONObject obj = response.getJSONObject(i);
ProductData news = new ProductData();
no = obj.getInt(TAG_NO);
news.addId(obj.getString(TAG_ID));
news.addJudul(obj.getString(TAG_JUDUL));
if (obj.getString(TAG_GAMBAR) != "")
news.addGambar(obj.getString(TAG_GAMBAR));
news.addDatetime(obj.getString(TAG_TGL));
news.addIsi(obj.getString(TAG_ISI));
// adding news to news array
newsList.add(news);
if (no > offSet)
offSet = no;
Log.d(TAG, "offSet " + offSet);
catch (JSONException e)
Log.e(TAG, "JSON Parsing error: " + e.getMessage());
// notifying list adapter about data changes
// so that it renders the list view with updated data
adapter.notifyDataSetChanged();
swipe.setRefreshing(false);
, new Response.ErrorListener()
@Override
public void onErrorResponse(VolleyError error)
VolleyLog.d(TAG, "Error: " + error.getMessage());
swipe.setRefreshing(false);
);
// Adding request to request queue
AppController.getInstance().addToRequestQueue(arrReq);
json android-volley
New contributor
Hi and welcome to SO. Please try to elaborate your problem, what is it exactly that you're stuck with. Also, take a moment to properly format your answer so that code can be distinguished from normal text. A well formed question is more likely to be noticed by someone who can answer your question. Hope it helps :)
– Vijay Chavda
Nov 10 at 15:56
Vijay has good feedback. Also make sure to check out How to Ask and help center for more help.
– LAD
Nov 10 at 19:49
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How do I insert data from MySQL into Gridview on Fragments? I've tried it with a coding method used for Activity. I've changed a lot but it's still wrong. This is my coding:
/**
* A simple @link Fragment subclass.
*/
public class Product extends Fragment implements
SwipeRefreshLayout.OnRefreshListener
GridView grid_product;
SwipeRefreshLayout swipe;
List<ProductData> newsList = new ArrayList<ProductData>();
private static final String TAG = Product.class.getSimpleName();
private static String url_list = Server.URL + "news.php?offset=";
private int offSet = 0;
int no;
ProductAdapter adapter;
public static final String TAG_NO = "no";
public static final String TAG_ID = "id";
public static final String TAG_JUDUL = "judul";
public static final String TAG_TGL = "tgl";
public static final String TAG_ISI = "isi";
public static final String TAG_GAMBAR = "gambar";
Handler handler;
Runnable runnable;
public Product()
// Required empty public constructor
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_product, container, false);
swipe = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
grid_product = (GridView) view.findViewById(R.id.grid_product);
setProduct();
return view;
private void setProduct()
adapter = new ProductAdapter(getActivity(), newsList);
grid_product.setAdapter(adapter);
grid_product.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
//pindah activity
startActivity(new Intent(
getActivity(), DetailActivity.class
));
);
I don't know where the mistake is:
swipe.setOnRefreshListener(this);
swipe.post(new Runnable()
@Override
public void run()
swipe.setRefreshing(true);
newsList.clear();
adapter.notifyDataSetChanged();
callNews(0);
);
grid_product.setOnScrollListener(new AbsListView.OnScrollListener()
private int currentVisibleItemCount;
private int currentScrollState;
private int currentFirstVisibleItem;
private int totalItem;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState)
this.currentScrollState = scrollState;
this.isScrollCompleted();
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
this.currentFirstVisibleItem = firstVisibleItem;
this.currentVisibleItemCount = visibleItemCount;
this.totalItem = totalItemCount;
private void isScrollCompleted()
if (totalItem - currentFirstVisibleItem == currentVisibleItemCount
&& this.currentScrollState == SCROLL_STATE_IDLE)
swipe.setRefreshing(true);
handler = new Handler();
runnable = new Runnable()
public void run()
callNews(offSet);
;
handler.postDelayed(runnable, 3000);
);
@Override
public void onRefresh()
newsList.clear();
adapter.notifyDataSetChanged();
callNews(0);
I don't know where the mistake is:
private void callNews(int page)
swipe.setRefreshing(true);
// Creating volley request obj
JsonArrayRequest arrReq = new JsonArrayRequest(url_list + page,
new Response.Listener<JSONArray>()
@Override
public void onResponse(JSONArray response)
Log.d(TAG, response.toString());
if (response.length() > 0)
// Parsing json
for (int i = 0; i < response.length(); i++)
try
JSONObject obj = response.getJSONObject(i);
ProductData news = new ProductData();
no = obj.getInt(TAG_NO);
news.addId(obj.getString(TAG_ID));
news.addJudul(obj.getString(TAG_JUDUL));
if (obj.getString(TAG_GAMBAR) != "")
news.addGambar(obj.getString(TAG_GAMBAR));
news.addDatetime(obj.getString(TAG_TGL));
news.addIsi(obj.getString(TAG_ISI));
// adding news to news array
newsList.add(news);
if (no > offSet)
offSet = no;
Log.d(TAG, "offSet " + offSet);
catch (JSONException e)
Log.e(TAG, "JSON Parsing error: " + e.getMessage());
// notifying list adapter about data changes
// so that it renders the list view with updated data
adapter.notifyDataSetChanged();
swipe.setRefreshing(false);
, new Response.ErrorListener()
@Override
public void onErrorResponse(VolleyError error)
VolleyLog.d(TAG, "Error: " + error.getMessage());
swipe.setRefreshing(false);
);
// Adding request to request queue
AppController.getInstance().addToRequestQueue(arrReq);
json android-volley
New contributor
How do I insert data from MySQL into Gridview on Fragments? I've tried it with a coding method used for Activity. I've changed a lot but it's still wrong. This is my coding:
/**
* A simple @link Fragment subclass.
*/
public class Product extends Fragment implements
SwipeRefreshLayout.OnRefreshListener
GridView grid_product;
SwipeRefreshLayout swipe;
List<ProductData> newsList = new ArrayList<ProductData>();
private static final String TAG = Product.class.getSimpleName();
private static String url_list = Server.URL + "news.php?offset=";
private int offSet = 0;
int no;
ProductAdapter adapter;
public static final String TAG_NO = "no";
public static final String TAG_ID = "id";
public static final String TAG_JUDUL = "judul";
public static final String TAG_TGL = "tgl";
public static final String TAG_ISI = "isi";
public static final String TAG_GAMBAR = "gambar";
Handler handler;
Runnable runnable;
public Product()
// Required empty public constructor
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_product, container, false);
swipe = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
grid_product = (GridView) view.findViewById(R.id.grid_product);
setProduct();
return view;
private void setProduct()
adapter = new ProductAdapter(getActivity(), newsList);
grid_product.setAdapter(adapter);
grid_product.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
//pindah activity
startActivity(new Intent(
getActivity(), DetailActivity.class
));
);
I don't know where the mistake is:
swipe.setOnRefreshListener(this);
swipe.post(new Runnable()
@Override
public void run()
swipe.setRefreshing(true);
newsList.clear();
adapter.notifyDataSetChanged();
callNews(0);
);
grid_product.setOnScrollListener(new AbsListView.OnScrollListener()
private int currentVisibleItemCount;
private int currentScrollState;
private int currentFirstVisibleItem;
private int totalItem;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState)
this.currentScrollState = scrollState;
this.isScrollCompleted();
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
this.currentFirstVisibleItem = firstVisibleItem;
this.currentVisibleItemCount = visibleItemCount;
this.totalItem = totalItemCount;
private void isScrollCompleted()
if (totalItem - currentFirstVisibleItem == currentVisibleItemCount
&& this.currentScrollState == SCROLL_STATE_IDLE)
swipe.setRefreshing(true);
handler = new Handler();
runnable = new Runnable()
public void run()
callNews(offSet);
;
handler.postDelayed(runnable, 3000);
);
@Override
public void onRefresh()
newsList.clear();
adapter.notifyDataSetChanged();
callNews(0);
I don't know where the mistake is:
private void callNews(int page)
swipe.setRefreshing(true);
// Creating volley request obj
JsonArrayRequest arrReq = new JsonArrayRequest(url_list + page,
new Response.Listener<JSONArray>()
@Override
public void onResponse(JSONArray response)
Log.d(TAG, response.toString());
if (response.length() > 0)
// Parsing json
for (int i = 0; i < response.length(); i++)
try
JSONObject obj = response.getJSONObject(i);
ProductData news = new ProductData();
no = obj.getInt(TAG_NO);
news.addId(obj.getString(TAG_ID));
news.addJudul(obj.getString(TAG_JUDUL));
if (obj.getString(TAG_GAMBAR) != "")
news.addGambar(obj.getString(TAG_GAMBAR));
news.addDatetime(obj.getString(TAG_TGL));
news.addIsi(obj.getString(TAG_ISI));
// adding news to news array
newsList.add(news);
if (no > offSet)
offSet = no;
Log.d(TAG, "offSet " + offSet);
catch (JSONException e)
Log.e(TAG, "JSON Parsing error: " + e.getMessage());
// notifying list adapter about data changes
// so that it renders the list view with updated data
adapter.notifyDataSetChanged();
swipe.setRefreshing(false);
, new Response.ErrorListener()
@Override
public void onErrorResponse(VolleyError error)
VolleyLog.d(TAG, "Error: " + error.getMessage());
swipe.setRefreshing(false);
);
// Adding request to request queue
AppController.getInstance().addToRequestQueue(arrReq);
json android-volley
json android-volley
New contributor
New contributor
edited Nov 10 at 22:47
Daniel Kaparunakis
2,11191626
2,11191626
New contributor
asked Nov 10 at 14:20
Nilzam yahya putra
1
1
New contributor
New contributor
Hi and welcome to SO. Please try to elaborate your problem, what is it exactly that you're stuck with. Also, take a moment to properly format your answer so that code can be distinguished from normal text. A well formed question is more likely to be noticed by someone who can answer your question. Hope it helps :)
– Vijay Chavda
Nov 10 at 15:56
Vijay has good feedback. Also make sure to check out How to Ask and help center for more help.
– LAD
Nov 10 at 19:49
add a comment |
Hi and welcome to SO. Please try to elaborate your problem, what is it exactly that you're stuck with. Also, take a moment to properly format your answer so that code can be distinguished from normal text. A well formed question is more likely to be noticed by someone who can answer your question. Hope it helps :)
– Vijay Chavda
Nov 10 at 15:56
Vijay has good feedback. Also make sure to check out How to Ask and help center for more help.
– LAD
Nov 10 at 19:49
Hi and welcome to SO. Please try to elaborate your problem, what is it exactly that you're stuck with. Also, take a moment to properly format your answer so that code can be distinguished from normal text. A well formed question is more likely to be noticed by someone who can answer your question. Hope it helps :)
– Vijay Chavda
Nov 10 at 15:56
Hi and welcome to SO. Please try to elaborate your problem, what is it exactly that you're stuck with. Also, take a moment to properly format your answer so that code can be distinguished from normal text. A well formed question is more likely to be noticed by someone who can answer your question. Hope it helps :)
– Vijay Chavda
Nov 10 at 15:56
Vijay has good feedback. Also make sure to check out How to Ask and help center for more help.
– LAD
Nov 10 at 19:49
Vijay has good feedback. Also make sure to check out How to Ask and help center for more help.
– LAD
Nov 10 at 19:49
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Nilzam yahya putra is a new contributor. Be nice, and check out our Code of Conduct.
Nilzam yahya putra is a new contributor. Be nice, and check out our Code of Conduct.
Nilzam yahya putra is a new contributor. Be nice, and check out our Code of Conduct.
Nilzam yahya putra is a new contributor. Be nice, and check out our Code of Conduct.
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%2f53239867%2fd-volley-1-5-onerrorresponse-product%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
Hi and welcome to SO. Please try to elaborate your problem, what is it exactly that you're stuck with. Also, take a moment to properly format your answer so that code can be distinguished from normal text. A well formed question is more likely to be noticed by someone who can answer your question. Hope it helps :)
– Vijay Chavda
Nov 10 at 15:56
Vijay has good feedback. Also make sure to check out How to Ask and help center for more help.
– LAD
Nov 10 at 19:49