• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps APK using Retrofit library crashes on start

  • Thread starter Thread starter Deleted User
  • Start date Start date
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:

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.
 
You're a bit stuck without the stack trace. You need to get the emulator working or deploy to a connected device.

 
Last edited by a moderator:
You're a bit stuck without the stack trace. You need to get the emulator working or deploy to a connected device.
I don't know why it won't work. The AVD comes up, I create a new Virtual device but it doesn't show on the list. I've tried running an avd outside the studio but it just shows the opening screen with "android" and a black background and does nothing.

I'll try again, if I open the avd outside the studio and drop the apk on it to install, will I still get the log info?
 
I used bluestacks and here's my logcat
Code:
05-06 18:51:27.174 2527-2810/com.google.android.gms I/FA-SVC: App measurement is starting up, version: 10298
05-06 18:51:27.244 2527-2993/com.google.android.gms I/FA-SVC: This instance being marked as an uploader
05-06 19:00:51.094 3799-3819/com.google.android.gms I/FA-SVC: App measurement is starting up, version: 10298
05-06 19:00:51.134 3799-3831/com.google.android.gms I/FA-SVC: This instance being marked as an uploader
05-06 19:01:03.194 3799-3807/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/metrics.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-06 19:01:03.194 3799-3807/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/help_responses.db.18' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
05-06 19:01:03.194 3799-3807/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.

How would I close this database?
I'm trying
Code:
response.errorBody().close();
before the end of the onResponse function
 
Last edited by a moderator:
Those messages are warnings, not errors.
What actually happens when you run your app?
 
Back
Top Bottom