JSON parsing and displaying into a recycler-card view fragment - android

I am trying to parse json with volley and display with recycler-card view in my tabbed fragment class in android. The json response is not displayed in the fragment. No errors or exceptions are shown. The app runs fine but no data is displayed. Take a look at the code below and tell me where I went wrong.
My Fragment Class
public class Latest_News extends Fragment {
private RecyclerView recyclerView;
private List<NewsItems> newsItemsList = new ArrayList<>();
private static final String TAG = Latest_News.class.getSimpleName();
private NewsItems newsItems;
public Latest_News() {
// Required empty public constructor
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
networkAvailable();
}
#Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View mView = inflater.inflate(R.layout.fragment_latest__news, container, false);
recyclerView = (RecyclerView) mView.findViewById(R.id.latestNews_recyclerView);
recyclerView.setHasFixedSize(true);
LinearLayoutManager llMan = new LinearLayoutManager(getContext());
llMan.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(llMan);
//recyclerView.setAdapter(new HomeFrag_RecyclerAdapter(getActivity(), newsItemsList));
if (networkAvailable()){
String url = "www.goal.com/api"; // fake url, pls dont mind
RequestQueue mRequestQueue = Volley.newRequestQueue(getActivity().getApplicationContext());
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
JSONObject newsObject = new JSONObject(response.toString());
String title = newsObject.getString("title");
String time = newsObject.getString("time");
String date = newsObject.getString("date");
String link = newsObject.getString("link");
String content = newsObject.getString("content");
String image = newsObject.getString("image" + "");
newsItems = new NewsItems();
newsItems.setImage_Id(Integer.parseInt(image));
newsItems.setNewsDate(date);
newsItems.setNewTitle(title);
newsItems.setNewsDesc(content);
newsItems.setNewsUrl(link);
newsItems.setNewsTime(time);
newsItemsList.add(newsItems);
} catch (JSONException e) {
e.printStackTrace();
}
recyclerView.setAdapter(new HomeFrag_RecyclerAdapter(getActivity(), newsItemsList));
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.i(TAG,"Error is: " + error.toString());
}
});
mRequestQueue.add(jsonObjectRequest);
}
else{
Toast.makeText(getActivity(), "Turn On Mobile Data or Wifi", Toast.LENGTH_SHORT).show();
}
return mView;
}
private boolean networkAvailable() {
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
boolean isAvailable = false;
if (networkInfo != null && networkInfo.isConnected()){
isAvailable = true;
}
return isAvailable;
}
}
Fragment Adapter Code is Shown Below:
public class HomeFrag_RecyclerAdapter extends RecyclerView.Adapter<HomeFrag_RecyclerAdapter.MyHolder> {
private Context context;
List<NewsItems> newsItemsList;
public HomeFrag_RecyclerAdapter(Context context, List<NewsItems> newsItemsList) {
this.context = context;
this.newsItemsList = newsItemsList;
}
#Override
public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.tab_frags_customview,parent,false);
return new MyHolder(v);
}
#Override
public void onBindViewHolder(MyHolder holder, int position) {
holder.title.setText(newsItemsList.get(position).getNewTitle());
holder.descn.setText(newsItemsList.get(position).getNewsDesc());
holder.time.setText(newsItemsList.get(position).getNewsTime());
holder.date.setText(newsItemsList.get(position).getNewsDate());
int i = position;
Picasso.with(context).load(newsItemsList.get(i).getImage_Id())
.centerCrop()
.error(R.drawable.ic_toc_black_24dp)
.into(holder.coverImg);
}
#Override
public int getItemCount() {
return newsItemsList.size();
}
public class MyHolder extends RecyclerView.ViewHolder{
private TextView title, descn, time, date;
private ImageView coverImg;
public MyHolder(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.news_titleTxt);
descn = (TextView) itemView.findViewById(R.id.news_DescTxt);
time = (TextView) itemView.findViewById(R.id.news_TimeTxt);
date = (TextView) itemView.findViewById(R.id.newsDateTxt);
coverImg = (ImageView) itemView.findViewById(R.id.newsImage);
}
}
}
Sample JSON to be parsed
<pre>
{
"0": {
"image": null,
"title": "Suresh Raina to miss 2nd ODI against New Zealand ",
"time": "08:29 pm ",
"date": "18 Oct ",
"content": "Indian cricketer Suresh Raina will miss the second ODI against New Zealand at Delhi on Thursday. ...",
"link": "https://full-story.newsinshorts.com/v1/article/a659a7be-0c4d-408c-851d-689da6b95498-1 "
},
"1": {
"image": null,
"title": "Harley-Davidson net income falls by 18.67% to $114 mn ",
"time": "08:29 pm ",
"date": "18 Oct ",
"content": "Motorcycle manufacturer Harley-Davidson on Tuesday reported an 18.67% year-on-year decline in net ...",
"link": "https://full-story.newsinshorts.com/v1/article/448cc170-1d42-4109-9c50-0fe3a3c36f44-1 "
},
"2": {
"image": null,
"title": "JNU to get 200 solar power operated street lights ",
"time": "08:27 pm ",
"date": "18 Oct ",
"content": "The Jawaharlal Nehru University in Delhi is set to get 200 solar power operated street lights, Vice ...",
"link": "https://full-story.newsinshorts.com/v1/article/96db26c8-be8f-4313-8d51-27fee9bd084d-1 "
},
"3": {
"image": null,
"title": "Patiala Court dismisses fake degree case against Irani ",
"time": "08:22 pm ",
"date": "18 Oct ",
"content": "Patiala House Court today dismissed a case against Union Minister Smriti Irani for allegedly ...",
"link": null
},
</pre>
XML layout for the Fragment Class above:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.joey.mydrawerapp.Fragments.HomeFragment_Fragments.Latest_News">
<!-- TODO: Update blank fragment layout -->
<include layout="#layout/recyclerview_layout"
android:id="#+id/latestNews_recyclerView"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="30sp"
android:gravity="center"
android:textStyle="bold"
android:text="Stay Tuned For Latest News" />
</RelativeLayout>

I generally don't parse JSON by hand anymore, I always use Gson or jackson. Provided your json is correct, your onResponse can look something like this:
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
#Override
public void onResponse(String response)
#Override
public void onResponse(Stringresponse) {
Gson gson = new Gson();
Map<String,Item> map = gson.fromJson(response, new TypeToken<Map<String,Item>>(){}.getType());
newsItemLists = new ArrayList(); // Clear the list if desired
for (Item item : map.values()) {
newsItems = new NewsItems();
// Copy all item attributes to newsItems here.
// if NewsItems is annotated correct, it can even be used to parse
// the json instead of the Item class below.
newsItemsList.add(newsItems);
}
// Move this line into the onCreate() initializng the adapter with an empty list.
//recyclerView.setAdapter(new HomeFrag_RecyclerAdapter(getActivity(), newsItemsList));
// add this to notify the adapter that the list has changed.
adapter.notifyDataSetChanged();
}
You will need a pojo for the gson object:
class Item {
String image;
String title;
String time;
String date;
String content;
String link;
}
Update
I've updated my answer just a bit to make a StringRequest Volley instead of a JSONRequest. We'll use the whole string response and parse it as JSON. Alternatively, you can change your Volley JsonObjectRequest to a JsonArrayRequest and receive a JSON array. Then you'll loop over each item in the array and parse it out.

Related

Iterating a JSONObject doesn't fill the spinner

I have an issue that i unable to understand i.e when i make an http request i get following JSONObject as response. I have to loop-iterate every keys, take the data that i need, build them in an object and fill the spinner, but i think there is something wrong in the loop or i don't know, cause when i take every object, alone without a loop, all work fine,
when i loop to build object and add to array list dynamically it don't work:
{
"Conteggio": 2,
"0": {
"Distributore Information": {
"id_distributore": "1",
"NomeDistributore": "Colonnina 0",
"litriiniziocolonna": "444",
}
},
"1": {
"Distributore Information": {
"id_distributore": "2",
"NomeDistributore": "Colonnina 1",
"litriiniziocolonna": "555",
}
}
}
I know that it's wrong loop through a JSONObject but i cant change this JSON.
Here the android code code:
private void getInfoColonnina(){
String url = "https://icantshowtheurlbutitworkfine_module.json";
final SharedPreferences myPref = getSharedPreferences("loginPref", MODE_PRIVATE);
final SharedPreferences.Editor myPreff = myPref.edit();
RequestQueue requestQueue = Volley.newRequestQueue(this);
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
List<DistrBean> distrBeansList = new ArrayList<>();
try {
JSONObject jsonObject = new JSONObject(response);
Iterator keys = jsonObject.keys();
while (keys.hasNext()) {
Object key = keys.next();
JSONObject value = jsonObject.getJSONObject((String) key);
JSONObject info = value.getJSONObject("Distributore Information");
String LitriColonnina1 = info.getString("litriiniziocolonna");
String NomeDistributore1 = info.getString("NomeDistributore");
String id_distributore1 = info.getString("id_distributore");
DistrBean distrBean = new DistrBean();
distrBean.setLitriColonnina(LitriColonnina1);
distrBean.setNomeDistributore(NomeDistributore1);
distrBean.setIdDistributore(id_distributore1);
distrBeansList.add(distrBean);
}
ArrayAdapter<DistrBean> adapter = new ArrayAdapter<DistrBean>(InizioTurnoActivity.this, android.R.layout.simple_spinner_item, distrBeansList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
DistrBean distrBean = (DistrBean) adapterView.getSelectedItem();
getSelectedDistr(distrBean);
}
#Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
Toast.makeText(InizioTurnoActivity.this, "CHIAMATA INFOCOLONNINA FALLITA", Toast.LENGTH_SHORT).show();
}
});
requestQueue.add(stringRequest);
}
public void getSelectedDistr(DistrBean v){
DistrBean distrBean = (DistrBean) spinner.getSelectedItem();
setDistrData(distrBean);
}
private void setDistrData(DistrBean distrBean){
String name = distrBean.getNomeDistributore();
String litri = distrBean.getLitriColonnina();
String id = distrBean.getIdDistributore();
tvProgressivo.setText(litri);
tvColonnina.setText(name);
Toast.makeText(this, "Hai selezionato " + name + "che ha litri: " + litri, Toast.LENGTH_LONG).show();
}
}
Can you guys help me? thank you in advance!
your json is not valid
{
"Conteggio": 2,
"0": {
"Distributore Information": {
"id_distributore": "1",
"NomeDistributore": "Colonnina 0",
"litriiniziocolonna": "444", //this line
}
},
"1": {
"Distributore Information": {
"id_distributore": "2",
"NomeDistributore": "Colonnina 1",
"litriiniziocolonna": "555", //this line
}
}
}
You should test your rest api on postman before integrating it in android app and use Gson library, response model to handle all json response. Gson library automatically parse data according to your model so you dont need to get data by specifying individual key.
I think that your parsing algorithm has issue.
Iterator keys = jsonObject.keys();
-> Conteggio, 0, 1
So you should skip one.

Troubles with JSON parsing

I'm working on a simple news app.
I need to fetch data from a remote server in JSON format then put it in view. I use TabLayout and recyclerView to display data categories and Volley for the query no API here.
The TabLayout is set automatically depending on data from JSON where I extract tabs title and the content of every tab is being displayed on recyclerView (Article title, image, content, links...) and rendered inside a fragment
I spent several hours trying to debug it without success., but whatever I do, no data is being displayed. Not sure what I'm doing wrong.
I know this is not the right place to ask for such things, but I'm a bit of a desperate and would need some experienced developer than me look at my problem.
How it works:
Activity launches BaseArticleFragment which calls a method that loads contents categories and bind the data to the views:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.fm = getSupportFragmentManager();
this.baseArticleFragment = new BaseArticleFragment();
FragmentTransaction ft = this.fm.beginTransaction();
ft.add(R.id.fragment_container, this.baseArticleFragment, TAB_LAYOUT_FRAGMENT_TAG);
ft.commit();
}
When launched, baseArticleFragment calls loadCategories() method inside its onActivityCreated() method:
#Override
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
loadCategories();
}
here is the loadCategories() method:
private void loadCategories(){
String url = "http://somesite.com/categories"; //link to grab the json data
ApplicationController.getInstance().addToRequestQueue(
new JsonObjectRequest(0, url, null, new Listener<JSONObject>() { //0 is the Volley code for GET method
#Override
public void onResponse(JSONObject jsonObject) {
BaseArticleFragment.categories = JSONParser.parseCategories(jsonObject);
BaseArticleFragment.this.mViewPager.setAdapter(
new RecyclerViewFragmentPagerAdapter(BaseArticleFragment.this.getChildFragmentManager(),
BaseArticleFragment.categories));
BaseArticleFragment.this.mTabLayout.setupWithViewPager(BaseArticleFragment.this.mViewPager);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError vError){
Log.d("BaseArticleFragment", "---Volley Error---");
Snackbar.make(BaseArticleFragment.this.mTabLayout, R.string.error_load_categories, Snackbar.LENGTH_SHORT)
.setAction(R.string.action_retry, new View.OnClickListener() {
#Override
public void onClick(View v) {
BaseArticleFragment.this.loadCategories();
}
}).show();
}
}));
}
I guess the problem may be with the query but not sure cause I think my logic here is good
EDIT :
Here is the JSON data I need to fetch:
[
{
"name": "Topic 1",
"tid": "2",
},
{
"name": "Topic 2",
"tid": "3",
},
{
"name": "Topic 3",
"tid": "4",
},
{
"name": "Topic 4",
"tid": "5",
},
{
"name": "Topic 5",
"tid": "6",
},
{
"name": "Topic 6",
"tid": "1415",
},
{
"name": "Topic 7",
"tid": "1414",
},
{
"name": "Topic 8",
"tid": "1298",
},
{
"name": "Topic 9",
"tid": "1301",
},
{
"name": "Topic 10",
"tid": "1299",
},
{
"name": "Topic 11",
"tid": "1302",
},
{
"name": "Topic 12",
"tid": "1300",
},
{
"name": "Topic 13",
"tid": "1297",
}
]
Edit 2:
I forget to paste the code for parseCategories() in my JSONPArser class
public static ArrayList<Category> parseCategories(JSONObject jsonObject) {
ArrayList<Category> categoryArrayList = new ArrayList<>();
try {
JSONArray categories = jsonObject.getJSONArray("categories");
Category all = new Category();
all.setTid("0");
all.setName(ApplicationController.getInstance().getString(R.string.tab_all));
categoryArrayList.add(all);
for (int i = 0; i < categories.length(); i++) {
JSONObject catObject = categories.getJSONObject(i);
Category category = new Category();
category.setTid(catObject.getString("tid"));
category.setName(catObject.getString("name"));
categoryArrayList.add(category);
}
return categoryArrayList;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
Try this #esQmo_,
StringRequest stringRequest = new StringRequest(url , new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
JSONArray jsonArray = new JSONArray(response);
ArrayList<Hashmap<String,String>> arraylist = new
ArrayList<>();
for (int i = 0; i < jsonArray.length(); i++) {
HashMap<String, String> hashMap = new HashMap<>();
String name =
jsonArray.getJSONObject(i).getString("name");
String tid =
jsonArray.getJSONObject(i).getString("tid");
hashMap.put("name", name);
hashMap.put("tid ", tid );
arraylist.add(hashMap);
Log.e("response",name + "\n" + tid);
}
attachAdapter(arraylist);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
});
RequestQueue queue = Volley.newRequestQueue(this);
queue.add(stringRequest);
//setting adapter data to the RecyclerView
private void attachAdapter(ArrayList<HashMap<String, String>>
arrayList) {
ExampleAdapter adapter = new ExampleAdapter(arrayList,this);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
}
This is the adapter class
public class ExampleAdpater extends RecyclerView.Adapter<ExampleAdpater.ExampleViewHolder>{
public ArrayList<HashMap<String,String>> arraylist;
public Context context;
public ExampleAdpater(ArrayList<HashMap<String, String>> arraylist, Context context) {
this.arraylist= arraylist;
this.context = context;
}
#NonNull
#Override
public ExampleViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.textLayout,viewGroup,false);
return new ExampleViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ExampleViewHolder viewHolder, int i) {
HashMap<String,String> hashMap = arraylist.get(i);
viewHolder.name.setText(hashMap.get("name"));
viewHolder.tid.setText(hashMap.get("tid"));
}
#Override
public int getItemCount() {
return arraylist.size();
}
public class ExampleViewHolder extends RecyclerView.ViewHolder{
TextView name,tid;
public ExampleViewHolder(#NonNull View itemView) {
super(itemView);
name = itemView.findViewById(R.id.name);
tid = itemView.findViewById(R.id.tid);
name.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(v.getContext(), ""+name.getText().toString(),
Toast.LENGTH_SHORT).show();
}
});
}
}
}
textLayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/name"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tid"
/>
</LinearLayout>
You forgot to add this thing at the end of the "load" method:
Volley.newRequestQueue(this).add(jsonRequest);
Try to add it...
Instead of using new RequestQueue, please use RequestQueue jsonQueue = new RequestQueue
Like this:
RequestQueue requestQueue = Volley.newRequestQueue(this);
String url = "https://someurl.com/api";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(url, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
JSONArray ja = new JSONArray(response);
for(int i = 0; i < ja.length(); i++)
{
JSONObject jo = ja.get(i);
String name = jo.getString("name");
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e("LOG", error.toString());
}
});
requestQueue.add(jsonObjectRequest);
Just check if you have set LayoutManager for recyclerView
recyclerView.setLayoutManager(new LinearLayoutManager(MyActivity.this));
Can we have your code and JSON data too? Since we can't read what's on your mind or on your computer... Plase make some edits to your post, add code and json data so we may help you.
Since you are getting a timeout error you can change the timeout value so that it will be willing to wait longer.
Try something like this:
jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(
MY_SOCKET_TIMEOUT_MS,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
where MY_SOCKET_TIMEOUT_MS is amount of time (in milliseconds) you want to wait before a timeout. Start with 5000 (5 seconds) and play around with it.
Do this before
requestQueue.add(jsonObjectRequest);

read json file form host showing white Screen in activity How can i solve this?

i want to read a JSON file from my host I made the internet permission and their is no exception in run just a White Screen and i don't
know what wrong,How can I solve this?
i expect a list that i made
json link here
The code is following
MainActivity:
package com.example.moham.twitter_ai;
public class MainActivity extends AppCompatActivity {
private List<tweets> tweetsList = new ArrayList<>();
private ListView listView;
private tweetAdapter madapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.list);
madapter = new tweetAdapter(this, tweetsList);
listView.setAdapter(madapter);
gettweets();
}
void gettweets() {
String url = "https://mohammedhemaid.000webhostapp.com/jsonTest.json";
StringRequest postRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
JSONObject object = new JSONObject(response);
String tweetText = object.getString("text");
String date = object.getString("timestamp_ms");
JSONObject user = object.getJSONObject("user");
String name = user.getString("name");
String screen_name = user.getString("screen_name");
tweets tw =
new tweets(name, screen_name, tweetText,date);
tweetsList.add(tw);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this,error.getMessage()
,Toast.LENGTH_LONG).show();
}
});
Volley.newRequestQueue(this).add(postRequest);
}
}
Adapter :
/**
* Created by moham on 27-Apr-18.
*/
public class tweetAdapter extends ArrayAdapter<tweets> {
public tweetAdapter(#NonNull Context context,List<tweets> tweets) {
super(context, 0,tweets);
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull
ViewGroup parent) {
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
}
tweets currentTweets = getItem(position);
TextView name = listItemView.findViewById(R.id.tv_name);
name.setText(currentTweets.getName());
TextView screenName = listItemView.findViewById(R.id.tv_screen_name);
screenName.setText(currentTweets.getScreenName());
TextView tweetText = listItemView.findViewById(R.id.tv_tweet_text);
tweetText.setText(currentTweets.getTweet());
Date dateObject = new Date(currentTweets.getTimeStamp());
TextView dateView = listItemView.findViewById(R.id.date);
// Format the date string (i.e. "Mar 3, 1984")
dateView.setText(currentTweets.getTimeStamp());
return listItemView;
}
}
error:(logCat)
JsonFile:
{"created_at":"Mon Mar 26 18:24:04 +0000 2018","id":978336799520100352,"id_str":"978336799520100352","text":"Ik wilde gwn een gratis gun en die krijg ik nu dus \ud83d\ude02 https:\/\/t.co\/AH38GYbUfk","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":964059877223084032,"id_str":"964059877223084032","name":"Wessel hoek","screen_name":"teddybeer025","location":null,"url":null,"description":"ik speel fortnite op de ps4","translator_type":"none","protected":false,"verified":false,"followers_count":2,"friends_count":10,"listed_count":1,"favourites_count":17,"statuses_count":7,"created_at":"Thu Feb 15 08:52:40 +0000 2018","utc_offset":null,"time_zone":null,"geo_enabled":false,"lang":"nl","contributors_enabled":false,"is_translator":false,"profile_background_color":"F5F8FA","profile_background_image_url":"","profile_background_image_url_https":"","profile_background_tile":false,"profile_link_color":"1DA1F2","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/964065505513476102\/4hCVGSKG_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/964065505513476102\/4hCVGSKG_normal.jpg","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"quote_count":0,"reply_count":0,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[{"url":"https:\/\/t.co\/AH38GYbUfk","expanded_url":"https:\/\/itunes.apple.com\/app\/id1333542838","display_url":"itunes.apple.com\/app\/id13335428\u2026","indices":[53,76]}],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"nl","timestamp_ms":"1522088644281"}
What Im I doing wrong ?
You're adding the empty list before you getting, so when you add items to the list the adapter dosn't know it needs to refresh. After you've added all new items to your list, call:
madapter.notifyDatasetChanged()
To refresh your adapter.
Moreover, you json doesn't seem to be a valid one. I've tested it with JsonLint and it looks like a list of tweets but it isn't enclosed in [] nor separated by commas.
If your json was a valid array of tweets, your code should look like this:
JSONArray objs = new JSONArray(response);
for(JSONObject object : objs){
String tweetText = object.getString("text");
String date = object.getString("timestamp_ms");
JSONObject user = object.getJSONObject("user");
String name = user.getString("name");
String screen_name = user.getString("screen_name");
tweets tw =
new tweets(name, screen_name, tweetText,date);
tweetsList.add(tw);
}
madapter.notifyDatasetChanged();

Error putting data from JSON response into Adapter (ListView)

I learned how to use ListView recently so I am not much proficient in it. I am facing a problem while adding the data from JSON response into the ListView. When I add hard-coded Strings into the ListView, it works fine. But gives nothing when putting data from JSON response.
Here is my activity (SupportedAds.java)
public class SupportedAds extends AppCompatActivity {
String[] Title;
String[] Content;
ListView list;
Offers offer;
ArrayList<Offers> offers = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_supported_ads);
list = findViewById(R.id.list);
/* Getting Supported Ads from the api*/
RequestQueue queue = Volley.newRequestQueue(SupportedAds.this);
final String URL_SUPPORTED_ADS = "http://lb-89089438.us-east-2.elb.amazonaws.com/api/offers";
StringRequest postRequest = new StringRequest(Request.Method.POST, URL_SUPPORTED_ADS,
new Response.Listener<String>()
{
#Override
public void onResponse(String response) {
JSONArray jsonResponse;
String offerContent;
String offerTitle;
// response
Log.wtf("POST api/offers", response);
try {
jsonResponse = new JSONArray(response);
Title = new String[jsonResponse.length()];
Content = new String[jsonResponse.length()];
for(int i=0; i < jsonResponse.length(); i++)
{
JSONObject jsonobject = jsonResponse.getJSONObject(i);
offerContent = jsonobject.getString("offercontent");
offerTitle = jsonobject.getString("offertitle");
offer = new Offers();
offer.setTitle(offerTitle);
offer.setContent(offerContent);
Log.e("Title", offerTitle); // shows correct values. No problem in JSON parsing or POST request
Log.e("Content", offerContent); // shows correct values. No problem in JSON parsing or POST request
offers.add(offer);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener()
{
#Override
public void onErrorResponse(VolleyError error) {
// error
Log.d("POST api/offers", error.toString());
}
}
) {
#Override
protected Map<String, String> getParams()
{
return new HashMap<>();
}
};
queue.add(postRequest);
/* Getting Supported Ads from the api*/
/* If i use these hard coded values, it works fine */
/*offer = new Offers();
offer.setTitle("Ad1");
offer.setContent("Advertisement #01 Description");
offers.add(offer);
offer = new Offers();
offer.setTitle("Ad2");
offer.setContent("Advertisement #02 Description");
offers.add(offer);
offer = new Offers();
offer.setTitle("Ad3");
offer.setContent("Advertisement #03 Description");
offers.add(offer);*/
list.setAdapter(new MyAdapter(getApplicationContext(), offers));
}
private class MyAdapter extends BaseAdapter {
private Context context;
private ArrayList<Offers> offers;
public MyAdapter(Context context, ArrayList<Offers> offers) {
this.context = context;
this.offers = offers;
}
#Override
public int getCount() {
return offers.size();
}
#Override
public Object getItem(int position) {
return offers.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
TwoLineListItem twoLineListItem;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
twoLineListItem = (TwoLineListItem) inflater.inflate(
android.R.layout.simple_list_item_2, null);
} else {
twoLineListItem = (TwoLineListItem) convertView;
}
TextView text1 = twoLineListItem.getText1();
TextView text2 = twoLineListItem.getText2();
text1.setText(offers.get(position).getTitle());
text2.setText(offers.get(position).getContent());
return twoLineListItem;
}
}
}
When I try to use data from JSON response (no data being displayed - sorry for the background color)
When I use hard-coded Strings (works fine in this case - sorry for the background color)
Layout file (activity_supported_ads.xml)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#color/lightgreen"
tools:context="com.fyp.mrisecondscreen.activity.SupportedAds">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/list">
</ListView>
</RelativeLayout>
Response from POST Request (I am sure that I have no problems in JSON response parsing as i use Log.e to display the extracted values and they're correct)
[
{
"offercontent": "Sample Description",
"offertitle": "Ad 1",
},
{
"offercontent": "42 inch TV",
"offertitle": "TV ",
},
{
"offercontent": "Coke Ad Offer description here",
"offertitle": "Coke",
},
{
"offercontent": "Cola Ad Offer description here",
"offertitle": "Cola Offer",
},
{
"offercontent": "Nestle Ad Offer description here",
"offertitle": "Nestle Cerelac Offer",
},
{
"offercontent": "New Year sale",
"offertitle": "Chocolate",
}
]
Please help me, I am unable to solve it after spending many hours..
Your code list.setAdapter(new MyAdapter(getApplicationContext(), offers)); executes before the request completes and hence there is no data to show. This line should execute after the parsing is done inside the onResponse method.

Can't use Volley to display two custom ListView

I am a beginner in android, and i am trying to use Volley to create a custom list which contains list of images and text description for each. There are two activities as list view, downloaded json data using volley, use OnItemClickListener to start other activity. the first activity is complete to run, when i click the other one, the Logcat got nothing to show, but the second Listview activity is blank only have title...
This is Logcat i don't it has usefully or not.
All my Logcat
05-22 16:09:32.549: V/Monotype(14980): SetAppTypeFace- try to flip, app = com.wangjian.klmeet_sightseeing
05-22 16:09:32.550: V/Monotype(14980): Typeface getFontPathFlipFont - systemFont = default
05-22 16:09:33.378: D/Volley(14980): [1] 2.onErrorResponse: MainActivity
my code look like this:
The first activity SightseeingActivity.java
public class SightseeingActivity extends Activity {
//Log tag
private static final String TAG = SightseeingActivity.class.getSimpleName();
//Sightseeing json url
private static final String url = "http://wangjian.site90.net/json/api_klmeet_sightseeing.json";
private ProgressDialog pDialog;
private List<Sight> sightList = new ArrayList<Sight>();
private ListView listView;
private CustomListAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sightseeing_activity);
listView = (ListView) findViewById(R.id.sight_list);
adapter = new CustomListAdapter(this, sightList);
listView.setAdapter(adapter);
pDialog = new ProgressDialog(this);
// Showing progress dialog before making http request
pDialog.setMessage("Loading...");
pDialog.show();
//changing action bar color
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#1b1b1b")));
//Creating volley request obj
JsonArrayRequest sightReq = new JsonArrayRequest(url,new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response){
Log.d(TAG, response.toString());
pDialog.dismiss();
for (int i = 0; i < response.length(); i++){
try{
JSONObject obj = response.getJSONObject(i);
Sight sight = new Sight();
sight.setTitle(obj.getString("title"));
sight.setThumbnailUrl(obj.getString("image"));
sight.setReadmore(obj.getString("readmore"));
sight.setPreintroduce(obj.getString("preintroduce"));
sight.setTag(obj.getString("tag"));
sightList.add(sight);
} catch (JSONException e) {
e.printStackTrace();
}
}
//notifying list adapter about data changes
//so that it renders the list view with updated data
adapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error){
VolleyLog.d(TAG, "Error: " + error.getMessage());
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(sightReq);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Class<? extends Activity> activityToSrart = null;
switch (position){
case 0:
activityToSrart = MainActivity.class;
break;
case 1:
activityToSrart = MerdekaSquare.class;
break;
}
Intent i = new Intent(getApplicationContext(), activityToSrart);
startActivity(i);
}
});
}
}
The second activity MainActivity
public class MainActivity extends Activity {
private static final String TAG = MainActivity.class.getSimpleName();
private ListView listView;
private FeedListAdapter listAdapter;
private List<FeedItem> feedItems;
private String URL_FEED = "http://wangjian.site90.net/json/api_klmeet_sightseeing_face.json";
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.list);
feedItems = new ArrayList<FeedItem>();
listAdapter = new FeedListAdapter(this, feedItems);
listView.setAdapter(listAdapter);
// These two lines not needed,
// just to get the look of facebook (changing background color & hiding the icon)
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#3b5998")));
getActionBar().setIcon(
new ColorDrawable(getResources().getColor(android.R.color.transparent)));
// We first check for cached request
Cache cache = AppController.getInstance().getRequestQueue().getCache();
Entry entry = cache.get(URL_FEED);
if (entry != null) {
// fetch the data from cache
try {
String data = new String(entry.data, "UTF-8");
try {
parseJsonFeed(new JSONObject(data));
} catch (JSONException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} else {
// making fresh volley request and getting json
JsonObjectRequest jsonReq = new JsonObjectRequest(Method.GET,
URL_FEED, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
VolleyLog.d(TAG, "Response: " + response.toString());
if (response != null) {
parseJsonFeed(response);
}
}
}, new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
}
});
// Adding request to volley request queue
AppController.getInstance().addToRequestQueue(jsonReq);
}
}
/**
* Parsing json reponse and passing the data to feed view list adapter
* */
private void parseJsonFeed(JSONObject response) {
try {
JSONArray feedArray = response.getJSONArray("feed");
for (int i = 0; i < feedArray.length(); i++) {
JSONObject feedObj = (JSONObject) feedArray.get(i);
FeedItem item = new FeedItem();
item.setId(feedObj.getInt("id"));
item.setName(feedObj.getString("name"));
// Image might be null sometimes
String image = feedObj.isNull("image") ? null : feedObj
.getString("image");
item.setImge(image);
item.setStatus(feedObj.getString("status"));
item.setProfilePic(feedObj.getString("profilePic"));
item.setTimeStamp(feedObj.getString("timeStamp"));
// url might be null sometimes
String feedUrl = feedObj.isNull("url") ? null : feedObj
.getString("url");
item.setUrl(feedUrl);
feedItems.add(item);
}
// notify data changes to list adapater
listAdapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
i will upload more code if needed.
FeedListAdapter.java
#SuppressLint("InflateParams")
public class FeedListAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<FeedItem> feedItems;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public FeedListAdapter(Activity activity, List<FeedItem> feedItems) {
this.activity = activity;
this.feedItems = feedItems;
}
#Override
public int getCount() {
return feedItems.size();
}
#Override
public Object getItem(int location) {
return feedItems.get(location);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.feed_item, null);
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
TextView name = (TextView) convertView.findViewById(R.id.name);
TextView timestamp = (TextView) convertView
.findViewById(R.id.timestamp);
TextView statusMsg = (TextView) convertView
.findViewById(R.id.txtStatusMsg);
TextView url = (TextView) convertView.findViewById(R.id.txtUrl);
NetworkImageView profilePic = (NetworkImageView) convertView
.findViewById(R.id.profilePic);
FeedImageView feedImageView = (FeedImageView) convertView
.findViewById(R.id.feedImage1);
FeedItem item = feedItems.get(position);
name.setText(item.getName());
// Converting timestamp into x ago format
CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(
Long.parseLong(item.getTimeStamp()),
System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
timestamp.setText(timeAgo);
// Chcek for empty status message
if (!TextUtils.isEmpty(item.getStatus())) {
statusMsg.setText(item.getStatus());
statusMsg.setVisibility(View.VISIBLE);
} else {
// status is empty, remove from view
statusMsg.setVisibility(View.GONE);
}
// Checking for null feed url
if (item.getUrl() != null) {
url.setText(Html.fromHtml("<a href=\"" + item.getUrl() + "\">"
+ item.getUrl() + "</a> "));
// Making url clickable
url.setMovementMethod(LinkMovementMethod.getInstance());
url.setVisibility(View.VISIBLE);
} else {
// url is null, remove from the view
url.setVisibility(View.GONE);
}
// user profile pic
profilePic.setImageUrl(item.getProfilePic(), imageLoader);
// Feed image
if (item.getImge() != null) {
feedImageView.setImageUrl(item.getImge(), imageLoader);
feedImageView.setVisibility(View.VISIBLE);
feedImageView
.setResponseObserver(new FeedImageView.ResponseObserver() {
#Override
public void onError() {
}
#Override
public void onSuccess() {
}
});
} else {
feedImageView.setVisibility(View.GONE);
}
return convertView;
}
}
FeedIteam
package com.wangjian.klmeet_sightseeing.model;
public class FeedItem {
private int id;
private String name, status, image, profilePic, timeStamp, url;
public FeedItem() {
}
public FeedItem(int id, String name, String image, String status,
String profilePic, String timeStamp, String url) {
super();
this.id = id;
this.name = name;
this.image = image;
this.status = status;
this.profilePic = profilePic;
this.timeStamp = timeStamp;
this.url = url;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImge() {
return image;
}
public void setImge(String image) {
this.image = image;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getProfilePic() {
return profilePic;
}
public void setProfilePic(String profilePic) {
this.profilePic = profilePic;
}
public String getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(String timeStamp) {
this.timeStamp = timeStamp;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
i upload XML file if needed
feed_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/feed_bg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="#dimen/feed_item_margin"
android:layout_marginRight="#dimen/feed_item_margin"
android:layout_marginTop="#dimen/feed_item_margin"
android:background="#drawable/bg_parent_rounded_corner"
android:orientation="vertical"
android:paddingBottom="#dimen/feed_item_padding_top_bottom"
android:paddingTop="#dimen/feed_item_padding_top_bottom" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="#dimen/feed_item_padding_left_right"
android:paddingRight="#dimen/feed_item_padding_left_right" >
<com.android.volley.toolbox.NetworkImageView
android:id="#+id/profilePic"
android:layout_width="#dimen/feed_item_profile_pic"
android:layout_height="#dimen/feed_item_profile_pic"
android:scaleType="fitCenter" >
</com.android.volley.toolbox.NetworkImageView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="#dimen/feed_item_profile_info_padd" >
<TextView
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/feed_item_profile_name"
android:textStyle="bold" />
<TextView
android:id="#+id/timestamp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/timestamp"
android:textSize="#dimen/feed_item_timestamp" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/txtStatusMsg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="#dimen/feed_item_status_pad_left_right"
android:paddingRight="#dimen/feed_item_status_pad_left_right"
android:paddingTop="#dimen/feed_item_status_pad_top" />
<TextView
android:id="#+id/txtUrl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:linksClickable="true"
android:paddingBottom="10dp"
android:paddingLeft="#dimen/feed_item_status_pad_left_right"
android:paddingRight="#dimen/feed_item_status_pad_left_right"
android:textColorLink="#color/link" />
<info.androidhive.listviewfeed.FeedImageView
android:id="#+id/feedImage1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:scaleType="fitXY"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
This is my first activity
the second one should be like this
But
JSON
{
"feed": [
{
"id": 1,
"name": "National Geographic Channel",
"image": "http://api.androidhive.info/feed/img/cosmos.jpg",
"status": "\"Science is a beautiful and emotional human endeavor,\" says Brannon Braga, executive producer and director. \"And Cosmos is all about making science an experience.\"",
"profilePic": "http://wangjian.site90.net/json/klcc.jpg",
"timeStamp": "1403375851930",
"url": null
},
{
"id": 2,
"name": "TIME",
"image": "http://api.androidhive.info/feed/img/time_best.jpg",
"status": "30 years of Cirque du Soleil's best photos",
"profilePic": "http://wangjian.site90.net/json/klcc.jpg,
"timeStamp": "1403375851930",
"url": "http://ti.me/1qW8MLB"
},
{
"id": 5,
"name": "Abraham Lincoln",
"image": null,
"status": "That some achieve great success, is proof to all that others can achieve it as well",
"profilePic": "http://wangjian.site90.net/json/klcc.jpg",
"timeStamp": "1403375851930",
"url": null
},
{
"id": 3,
"name": "Discovery",
"image": "http://api.androidhive.info/feed/img/discovery_mos.jpg",
"status": "A team of Austrian scientists has developed a laser system that causes fruit flies to dance.",
"profilePic": "http://wangjian.site90.net/json/klcc.jpg",
"timeStamp": "1403375851930",
"url": "http://dsc.tv/xmMxD"
},
{
"id": 4,
"name": "Ravi Tamada",
"image": "http://api.androidhive.info/feed/img/nav_drawer.jpg",
"status": "Android Sliding Menu using Navigation Drawer",
"profilePic": "http://wangjian.site90.net/json/klcc.jpg",
"timeStamp": "1403375851930",
"url": "http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/"
},
{
"id": 6,
"name": "KTM",
"image": "http://api.androidhive.info/feed/img/ktm_1290.jpg",
"status": "\"The Beast\" KTM 1290 Super Duke",
"profilePic": "http://wangjian.site90.net/json/klcc.jpg",
"timeStamp": "1403375851930",
"url": ""
},
{
"id": 7,
"name": "Harley-Davidson",
"image": "http://api.androidhive.info/feed/img/harley_bike.jpg",
"status": "We’re assembling riders of every style, bike, and passion. If you ride with conviction, ride with us. You have 24 days to get ready for World Ride. Prepare by visiting:",
"profilePic": "http://wangjian.site90.net/json/klcc.jpg",
"timeStamp": "1403375851930",
"url": "http://bit.ly/1wmBWaN"
},
{
"id": 8,
"name": "Rock & Girl",
"image": "http://api.androidhive.info/feed/img/rock.jpg",
"status": "A long time back...",
"profilePic": "http://wangjian.site90.net/json/klcc.jpg",
"timeStamp": "1403375851930",
"url": ""
},
{
"id": 8,
"name": "Gandhi",
"image": null,
"status": "An eye for an eye will make the whole world blind.",
"profilePic": "http://wangjian.site90.net/json/klcc.jpg",
"timeStamp": "1403375851930",
"url": ""
},
{
"id": 9,
"name": "LIFE",
"image": "http://api.androidhive.info/feed/img/life_photo.jpg",
"status": "In 1965, LIFE photographer Bill Ray spent weeks with the Hells Angels, but his amazing photos never ran in the magazine",
"profilePic": "http://wangjian.site90.net/json/klcc.jpg",
"timeStamp": "1403375851930",
"url": "http://ti.me/1rfcQa4"
},
{
"id": 10,
"name": "Shakira",
"image": "http://api.androidhive.info/feed/img/shakira_la_la.png",
"status": "Download La La La (Brazil 2014) from iTunes:",
"profilePic": "http://wangjian.site90.net/json/klcc.jpg",
"timeStamp": "1403375851930",
"url": "http://smarturl.it/FWCalbum?IQid=sh"
},
{
"id": 11,
"name": "A. R. rahman",
"image": "http://api.androidhive.info/feed/img/ar_bw.jpg",
"status": "",
"profilePic": "http://wangjian.site90.net/json/klcc.jpg",
"timeStamp": "1403375851930",
"url": ""
}
]
}
I'm a newbie at this stuff so any help will be appreciated. Thanks in Advance.!
Firstly, private String URL_FEED = "http://wangjian.site90.net/json/api_klmeet_sightseeing_face.json"; in your MainActivity doesn't exist and when I tried it in AdvanceRestClient I got this:
So I tried looking more into directory structure of your WS and found there isn't any such URL you have mentioned as above.
Further more, I got security issues while trying to access your directory:
I am not sure what you are looking for seriously, but you could try with a valid URL in MainActivity and it should work fine.
Security issue creep me out literaly. :(

Categories

Resources