Hello guys some one can help me or tell me a solutions for that bugs?
*ERRORS*
E/dalvikvm: Could not find class
'android.graphics.drawable.RippleDrawable', referenced from method
android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.grability.apptest, PID: 7752
java.lang.RuntimeException: An error occured while
executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at
java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at
java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at
java.util.concurrent.FutureTask.run(FutureTask.java:242)
at
android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NullPointerException
at
com.grability.apptest.MainActivity$JsonToFeed.doInBackground(MainActivity.java:172)
at
com.grability.apptest.MainActivity$JsonToFeed.doInBackground(MainActivity.java:135)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at
java.util.concurrent.FutureTask.run(FutureTask.java:237)
at
android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
SCRIPT
package com.grability.apptest;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class MainActivity extends AppCompatActivity {
Feed feed = null;
ListView lista;
ArrayAdapter adaptador;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lista = (ListView) findViewById(R.id.listProducts);
JsonToFeed fetcher = new JsonToFeed();
fetcher.execute();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.posts, menu);
return true;
}
private void handlePostsList() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (feed != null) {
adaptador = new Adapter(getBaseContext(), feed.getEntry());
lista.setAdapter(adaptador);
} else {
Toast.makeText(
getBaseContext(),
"Ocurrió un error de Parsing Json",
Toast.LENGTH_SHORT)
.show();
}
// for(Entry post : this.feed.getEntry()) {
// Toast.makeText(this, post.getTitle().getLabel(),
Toast.LENGTH_SHORT).show();
// }
}
});
}
private void failedLoadingPosts() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getBaseContext(), "Failed to load Posts. Have a
look at LogCat.", Toast.LENGTH_SHORT).show();
}
});
}
private class PostFetcher extends AsyncTask<Void, Void, String> {
private static final String TAG = "feed";
public static final String SERVER_URL =
"https://itunes.apple.com/us/rss/topfreeapplications/limit=20/json";
@Override
protected String doInBackground(Void... params) {
try {
//Create an HTTP client
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(SERVER_URL);
//Perform the request and check the status code
HttpResponse response = client.execute(post);
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == 200) {
HttpEntity entity = response.getEntity();Log.e(TAG,
"MENSAJE " + entity.getContent());
InputStream content = entity.getContent();
try {
//Read the server response and attempt to parse it as
JSON
Log.e(TAG, "MENSAJE " + content.toString());
Reader reader = new InputStreamReader(content);
Log.e(TAG, "MENSAJE " + reader.toString());/*
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setDateFormat("M/d/yy hh:mm a");
Gson gson = gsonBuilder.create();
List<Entry> newEntry = new ArrayList<Entry>();
newEntry = Arrays.asList(gson.fromJson(reader,
Entry[].class));*/
content.close();
// handlePostsList();
} catch (Exception ex) {
Log.e(TAG, "Failed to parse JSON due to: " + ex);
failedLoadingPosts();
}
} else {
Log.e(TAG, "Server responded with status code: " +
statusLine.getStatusCode());
failedLoadingPosts();
}
} catch(Exception ex) {
Log.e(TAG, "Failed to send HTTP POST request due to: " + ex);
failedLoadingPosts();
}
return null;
}
}
private class JsonToFeed extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
Author newAuthor = null;
List<Entry> newEntry = null;
Updated newUpdated = null;
Rights newRights = null;
Title newTitle = null;
Icon newIcon = null;
List<Link> newLink = null;
Id newId = null;
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
String jsonStr =
sh.makeServiceCall("https://itunes.apple.com/us/rss/topfreeapplications/limit=20/json",
ServiceHandler.GET);
try {
JSONObject json = new JSONObject(jsonStr);
JSONObject feedObj = json.getJSONObject("feed");
if (feedObj != null) {
newAuthor = new Author(
new
Name(feedObj.getJSONObject("author").getJSONObject("name").getString("label")),
new
Uri(feedObj.getJSONObject("author").getJSONObject("uri").getString("label"))
);
JSONArray entries = feedObj.getJSONArray("entry");
int entriesCount = entries.length();
for (int i = 0; i < entriesCount; i++) {
JSONObject entry = (JSONObject) entries.get(i);
List<ImImage> tempImgs = null; // Creamos listado vacio
de imagenes
JSONArray appImages = entry.getJSONArray("im:image");
// Obtenemos listado de imagenes
for (int g = 0; g < appImages.length(); g++) {
JSONObject images = (JSONObject) appImages.get(g);
tempImgs.add(new ImImage(images.getString("label"),
GetAttributes(images.getJSONObject("attributes"))));
}
newEntry.add(
new Entry(
new
ImName(entry.getJSONObject("im:name").getString("label")),
tempImgs,
new
Summary(entry.getJSONObject("summary").getString("label")),
new
ImPrice(entry.getJSONObject("im:price").getString("label"),
GetAttributes(entry.getJSONObject("im:contentType").getJSONObject("attributes"))),
new
ImContentType(GetAttributes(entry.getJSONObject("im:contentType").getJSONObject("attributes"))),
new
Rights(entry.getJSONObject("rights").getString("label")),
new
Title(entry.getJSONObject("title").getString("label")),
new
Link(GetAttributes(entry.getJSONObject("link").getJSONObject("attributes"))),
new
Id(entry.getJSONObject("id").getString("label"),
GetAttributes(entry.getJSONObject("id").getJSONObject("attributes"))),
new
ImArtist(entry.getJSONObject("im:artist").getString("label"),
GetAttributes(entry.getJSONObject("im:artist").getJSONObject("attributes"))),
new
Category(GetAttributes(entry.getJSONObject("category").getJSONObject("attributes"))),
new
ImReleaseDate(entry.getJSONObject("im:releaseDate").getString("label"),
GetAttributes(entry.getJSONObject("im:releaseDate").getJSONObject("attributes")))
)
);
}
newUpdated = new
Updated(feedObj.getJSONObject("updated").getString("label"));
newRights = new
Rights(feedObj.getJSONObject("rights").getString("label"));
newTitle = new
Title(feedObj.getJSONObject("title").getString("label"));
newIcon = new
Icon(feedObj.getJSONObject("icon").getString("label"));
JSONArray tempLink = feedObj.getJSONArray("link");
for (int i = 0; i < tempLink.length(); i++) {
JSONObject tempData = (JSONObject) tempLink.get(i);
newLink.add(new
Link(GetAttributes(tempData.getJSONObject("attributes"))));
}
newId = new
Id(feedObj.getJSONObject("id").getString("label"),
GetAttributes(feedObj.getJSONObject("id").getJSONObject("label").getJSONObject("attributes")));
// handlePostsList();
feed = new Feed(newAuthor, newEntry, newUpdated, newRights,
newTitle, newIcon, newLink, newId);
}
} catch (JSONException e) {
e.printStackTrace();
//TODO Mostrar alerta
failedLoadingPosts();
}
return null;
}
}
private Attributes GetAttributes(JSONObject array) throws JSONException {
String label = null;
String rel = null;
String type = null;
String href = null;
String schema = null;
String term = null;
String imId = null;
String imBundleId = null;
String amount = null;
String currency = null;
String height = null;
if (!array.isNull("label"))
label = array.getString("label");
if (!array.isNull("rel"))
rel = array.getString("rel");
if (!array.isNull("type"))
type = array.getString("type");
if (!array.isNull("href"))
href = array.getString("href");
if (!array.isNull("schema"))
schema = array.getString("schema");
if (!array.isNull("term"))
term = array.getString("term");
if (!array.isNull("im:id"))
imId = array.getString("im:id");
if (!array.isNull("im:bundleId"))
imBundleId = array.getString("im:bundleId");
if (!array.isNull("amount"))
amount = array.getString("amount");
if (!array.isNull("currency"))
currency = array.getString("currency");
if (!array.isNull("height"))
height = array.getString("height");
//Log.d("Mensaje", array.getString("rel"));
return new
Attributes(label,rel,type,href,schema,term,imId,imBundleId,amount,currency,height);
}
}
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/52b4b5c0-3bf7-4b22-ac5c-68856aad9557%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.