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);












share|improve this question























  • 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














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);












share|improve this question























  • 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












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);












share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 22:47









Daniel Kaparunakis

2,11691627




2,11691627










asked Nov 10 at 14:20









Nilzam yahya putra

1




1











  • 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










  • 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

















active

oldest

votes











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',
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
);



);













draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo