-1

Hi I have problem with response from REST. I receive Object Json parse it and everything look fine but when i try add it to Realm i get Null Pointer Exception. This is link to my project: https://github.com/666Angelus666/MobileDealer

In MainActivity I call function synchronizeContractorsItems then in the 3-th Call i'm get the error. Line where i get error

Angel666
  • 5
  • 4

2 Answers2

0

I have seen your code. I think this issue is because you did not initialize your orderDAO object in your activity you have to initialize your orderDAO object before using

orderDAO = new OrderDAO();


Call<OrderResponse> orderResponseCall = apiService.getOrdersList();
        orderResponseCall.enqueue(new Callback<OrderResponse>() {
            @Override
            public void onResponse(Call<OrderResponse> call, Response<OrderResponse> response) {
                orderList = response.body().getOrdersList();

                for (Order order : orderList) {
                    try {
                        orderDAO.insertOrUpdate(order);
                    } catch (Exception e) {
                        Log.d("REST", "Error");
                        e.printStackTrace();
                    }
                }
            }`

I think this may solve your problem.

UltimateDevil
  • 2,807
  • 2
  • 18
  • 31
0

The suspect may be your order could be null, may be a null check would help

 public void insertOrUpdate(Order order) {

 if(order != null)

 {

    realm.beginTransaction();
    realm.insertOrUpdate(order);
    realm.commitTransaction();

 }

    }`
UltimateDevil
  • 2,807
  • 2
  • 18
  • 31
Rizwan
  • 2,369
  • 22
  • 27