Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. Error en la peticion: com.android.volley.ParseError: org.json.JSONException: Value [{"id":1,"name":"Test","description":"some description","price":3.1416,"finish":"some finish","color":"some great color","suitability":"where tu use it","status":true,"picture":null}
  2.  
  3. /****** This activity is used for show Tiles ******/
  4. public class CatalogActivity extends Activity {
  5.  
  6. /******* Variable It is used. to indicate how many fields are shown ******/
  7. private GridLayoutManager mLayout;
  8. private static TileAdapter mTileAdapter;
  9.  
  10.  
  11. /****** Context to use the Strings ******/
  12. private static Context mContext;
  13.  
  14. /****** Instances of gson, bus, realm, requestque, It is used to connect with web service ******/
  15. private static Gson mGson;
  16. private static RequestQueue mRequestQueue;
  17. private static Bus mBus;
  18. private static Realm mRealm;
  19.  
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. setContentView(R.layout.activity_catalog);
  23.  
  24. Realm.init(this);
  25. RealmConfiguration config = new RealmConfiguration.Builder().build();
  26. Realm.setDefaultConfiguration(config);
  27. mRealm = Realm.getDefaultInstance();
  28.  
  29. mGson = new Gson();
  30. mRequestQueue = Volley.newRequestQueue(this);
  31. mBus = new Bus();
  32.  
  33. RecyclerView MyRecyclerView = (RecyclerView) findViewById(R.id.recycler_tile);
  34. mLayout = new GridLayoutManager(CatalogActivity.this,4);
  35. MyRecyclerView.setLayoutManager(mLayout);
  36. MyRecyclerView.setItemAnimator(new DefaultItemAnimator());
  37. loadTiles();
  38. List<TileModel> realmResults = CatalogActivity
  39. .getRealm()
  40. .where(TileModel.class)
  41. .findAll();
  42. mTileAdapter = new TileAdapter(realmResults, CatalogActivity.this);
  43. MyRecyclerView.setAdapter(mTileAdapter);
  44.  
  45. }
  46.  
  47. /****** Helpers to connect with web service ******/
  48. public static Gson getGson() {
  49. return mGson;
  50. }
  51.  
  52. public static RequestQueue getRequestQueue() {
  53. return mRequestQueue;
  54. }
  55.  
  56. public static Bus getBus() {
  57. return mBus;
  58. }
  59.  
  60. public static Realm getRealm() {
  61. return mRealm;
  62. }
  63.  
  64. /****** This methos is used for load Tiles ******/
  65. public static void loadTiles() {
  66.  
  67. JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
  68. JSONKeys.KEY_URL_ALL_TILES, new Response.Listener<JSONObject>() {
  69. @Override
  70. public void onResponse(JSONObject response) {
  71. Log.e("Response", response.toString());
  72. try {
  73. JSONArray mJsonArray = response.getJSONArray(JSONKeys.KEY_NAME);
  74. for (int i = 0; i < mJsonArray.length(); i++) {
  75. JSONObject mJsonObject = mJsonArray.getJSONObject(i);
  76. TileModel mTileModel = CatalogActivity.getGson()
  77. .fromJson(mJsonObject.toString(),
  78. TileModel.class);
  79. CatalogActivity.getRealm().beginTransaction();
  80. CatalogActivity.getRealm().copyToRealmOrUpdate(mTileModel);
  81. CatalogActivity.getRealm().commitTransaction();
  82. Log.e("Agregando Pisos", mTileModel.getName());
  83. }
  84. CatalogActivity.getBus().post(new SuccessLoadTilesEvent(mContext
  85. .getString(R.string.message_aggregate_tiles)));
  86. } catch (JSONException e) {
  87. Log.e("Error al parcear", e.toString());
  88. e.printStackTrace();
  89. }
  90. }
  91. }, new Response.ErrorListener() {
  92. @Override
  93. public void onErrorResponse(VolleyError error) {
  94. Log.e("Error en la peticion", error.toString());
  95. }
  96. });
  97. CatalogActivity.getRequestQueue().add(jsonObjectRequest);
  98. }
  99. }
  100.  
  101. [{
  102. "id": 1,
  103. "name": "Test",
  104. "description": "some description",
  105. "price": 3.1416,
  106. "finish": "some finish",
  107. "color": "some great color",
  108. "suitability": "where tu use it",
  109. "status": true,
  110. "picture": null
  111. }]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement