D
Deleted User
Guest
I'm trying to make an app that accesses json data from a server.It basically finds all the objects called "bubble". Finds out how many there are, and their collective shop price after discounts. I built and signed the app succesfully and sent it to my phone but after installing, whenever I click on it I get "Unfortunately xxxxx is no longer responding"
I'm using the tutorial here: http://www.androidhive.info/2016/05/android-working-with-retrofit-http-library/
I've set up all the other files except the adaptor, without all the imports and stuff, this is what my main activity looks like:
and this is my xml
For some reason the AVD isn't working for me and my usb is faulty so I can only send the app to my phone and test it, which means I can't use the logcat in android studio. I did find some logcat android apps and they mention somehng about the volley library I was using earlier but I removed this libraries dependencies and cut it out of the project. Somehow I think it's still affecting it. I'd really appreciate some help with this. I've been stuck on it for a while now.
I'm using the tutorial here: http://www.androidhive.info/2016/05/android-working-with-retrofit-http-library/
I've set up all the other files except the adaptor, without all the imports and stuff, this is what my main activity looks like:
Code:
public class MainActivity extends AppCompatActivity {
int num;
double price;
TextView numText;
TextView priceText;
private static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
numText = (TextView)findViewById(R.id.number);
priceText = (TextView)findViewById(R.id.priceOf);
ApiInterface apiService =
ApiClient.getClient().create(ApiInterface.class);
Call<OrderResponse> call = apiService.getPaidOrders();
call.enqueue(new Callback<OrderResponse>() {
@Override
public void onResponse(Call<OrderResponse> call, retrofit2.Response<OrderResponse> response) {
List<Order> orders = response.body().getOrders();
Log.d(TAG, "Number of movies received: " + orders.size());
//solution
num=0;
price=0.0;
for (Order order: orders
) {
if(order.inactive()==null) {
List<Map<String, Object>> items = order.getallobjects();
for (Map<String, Object> item: items
) {
if(item.get("name") == "bubble") {
num += (int) item.get("amount");
double tempPrice= (double) item.get("price")- (double) item.get("discount");
price+=tempPrice;
}
}
}
}
numText.setText(String.valueOf(num));
priceText.setText(String.valueOf(price));
}
@Override
public void onFailure(Call<OrderResponse>call, Throwable t) {
// Log error here since request failed
Log.e(TAG, t.toString());
}
});
}
}
and this is my xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
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:weightSum="1"
tools:context=".activity.MainActivity">
<TextView
android:id="@+id/number"
android:layout_width="315dp"
android:layout_height="129dp"
android:layout_weight="0.34"
android:text="Hello World!" />
<TextView
android:id="@+id/priceOf"
android:layout_width="316dp"
android:layout_height="132dp"
android:layout_weight="0.41"
android:text="TextView" />
</LinearLayout>
For some reason the AVD isn't working for me and my usb is faulty so I can only send the app to my phone and test it, which means I can't use the logcat in android studio. I did find some logcat android apps and they mention somehng about the volley library I was using earlier but I removed this libraries dependencies and cut it out of the project. Somehow I think it's still affecting it. I'd really appreciate some help with this. I've been stuck on it for a while now.