Home » Java » Asynchronous Http request error: E/NetworkUtilities: [MTK_net]ss.ss_family:2

Asynchronous Http request error: E/NetworkUtilities: [MTK_net]ss.ss_family:2

Posted by: admin August 10, 2018 Leave a comment

Questions:

I have created a pretty simple currency API app which was supposed to show exchange rate of euro for every other currency on the Recycler View split. I know that my MVP pattern isn’t real MVP, I didn’t fix my code because of this error which I couldn’t get rid of.

Before some changes I had no buffer locked error but now it appears (but I guess it doesn’t matter that much as ss family one).
I can read in Run log that JSON object is correctly loaded after network errors but it’s too late.

Github program: https://github.com/kudziadawid/Fixer-Currency

Below I pasted error log and 3 the most important classes:

Error:

08-05 00:00:15.925 19806-20007/com.kudziadawid.fixercurrency E/NetworkUtilities: [MTK_net]ss.ss_family:10
08-05 00:00:15.925 19806-20007/com.kudziadawid.fixercurrency E/NetworkUtilities: [MTK_net]ss.ss_family:2
08-05 00:00:15.925 19806-20007/com.kudziadawid.fixercurrency E/NetworkUtilities: [MTK_net]ss.ss_family:2
08-05 00:00:39.298 19806-19989/com.kudziadawid.fixercurrency E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f9dd73b80
08-05 00:00:41.231 19806-19989/com.kudziadawid.fixercurrency E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7fa3bc94e0

MainActivity.java (without imports)

    public class MainActivity extends AppCompatActivity {

RecyclerView currencyListRV;

CurrencyListPresenter currencyListPresenter;
CurrencyListAdapter currencyListAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    JodaTimeAndroid.init(this);
    Timber.plant(new Timber.DebugTree());

    currencyListRV = findViewById(R.id.currency_list);

    final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    currencyListRV.setLayoutManager(layoutManager);

    currencyListPresenter = new CurrencyListPresenter();

    currencyListAdapter = new CurrencyListAdapter(currencyListPresenter, this, currencyListRV);
    currencyListRV.setAdapter(currencyListAdapter);
}
}

CurrencyListPresenter.java (without imports)

    public class CurrencyListPresenter extends BasePresenter {

private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormat.forPattern("dd-MM-yyyy");
private static final DateTimeFormatter LINK_DATE_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd");
private static final String BASE_URL = "http://data.fixer.io/api/";
private static final String ACCESS_KEY = "?access_key=75c4194d62f0eb5d093405e35997df29";

Currency currency;
DateTime actualDateTime;
JSONObject jsonObject;

public CurrencyListPresenter() {
    currency = new Currency();
    actualDateTime = new DateTime();

    String tempString;
    tempString = actualDateTime.toString(LINK_DATE_FORMATTER);
    String url = BASE_URL + tempString + ACCESS_KEY;

    jsonObject = FixerRestClient.getFixerObject(url);
}

public String itemText(int position) throws JSONException {
    StringBuilder stringBuilder = new StringBuilder();
    int whichDayBehind = position / currency.getCurrencyListSize();
    int positionInCurrency = position % currency.getCurrencyListSize();

        if (positionInCurrency == 0) {
            String tempString;
            DateTime tempDateTime;
            tempDateTime = actualDateTime.minusDays(whichDayBehind);
            tempString = tempDateTime.toString(DATE_FORMATTER);
            stringBuilder.append(currency.getCurrencyListItem(0) + ": " + tempString);
        } else {
            String tempString;
            DateTime tempDateTime;
            tempDateTime = actualDateTime.minusDays(whichDayBehind);
            tempString = tempDateTime.toString(LINK_DATE_FORMATTER);
            String url = BASE_URL + tempString + ACCESS_KEY;
            jsonObject = FixerRestClient.getFixerObject(url);
            stringBuilder.append(currency.getCurrencyListItem(positionInCurrency) + ": "
                    + String.valueOf(jsonObject.getJSONObject("rates").getDouble(currency.getCurrencyListItem(positionInCurrency))));
        }
    return stringBuilder.toString();
}
}

CurrencyListAdapter.java (without imports)

    public class CurrencyListAdapter extends RecyclerView.Adapter {

CurrencyListPresenter currencyListPresenter;
Activity activity;
RecyclerView currencyListRV;

private class ViewHolder extends RecyclerView.ViewHolder {
    public TextView singleItem;

    public ViewHolder(View pItem) {
        super(pItem);
        singleItem = pItem.findViewById(R.id.tv_item_text);
    }
}

public CurrencyListAdapter(CurrencyListPresenter currencyListPresenter, Activity activity, RecyclerView currencyListRV) {
    this.activity = activity;
    this.currencyListPresenter = currencyListPresenter;
    this.currencyListRV = currencyListRV;
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.view_currency_list_item, parent, false);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(activity, CurrencyDetailActivity.class);
            int itemPosition = currencyListRV.getChildAdapterPosition(v);
            String itemText = "";
            try {
                itemText = currencyListPresenter.itemText(itemPosition);
            } catch (JSONException e) {
                Timber.d(e, "JSONException onCreateViewHolder itemText method");
            }
            intent.putExtra("itemText", itemText);
            activity.startActivity(intent);
        }
    });

    return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
    String temp = "";

    try {
        temp = currencyListPresenter.itemText(position);
    } catch (JSONException e) {
        Timber.d(e, "JSONException onBindViewHolder itemText method");
    }
    ((ViewHolder) holder).singleItem.setText(temp);
}

@Override
public int getItemCount() {
   return Integer.MAX_VALUE;
}
}
Answers: