-4

I am trying to log the following in Android Java:

    Log.i("Build.VERSION.SDK_INT", Build.VERSION.SDK_INT.toString());
    Log.i("Build.VERSION_CODES.M", Build.VERSION_CODES.M.toString());
    Log.i("Build.VERSION_CODES.O", Build.VERSION_CODES.O.toString());
    Log.i("getReactApplicationContext().checkCallingOrSelfPermission(Manifest.permission.READ_SMS", getReactApplicationContext().checkCallingOrSelfPermission(Manifest.permission.READ_SMS).toString());
    Log.i("getReactApplicationContext().checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_NUMBERS)", getReactApplicationContext().checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_NUMBERS).toString());
    Log.i("getReactApplicationContext().getSystemService(Context.TELEPHONY_SERVICE)", getReactApplicationContext().getSystemService(Context.TELEPHONY_SERVICE).toString());
    Log.i("Build.VERSION_CODES.O", Build.VERSION_CODES.O.toString());

But I get the error error: int cannot be dereferenced on every line.

How can I log these objects in logcat?

4
  • Thanks, but is every one of these values an integer? My question is how can I log these objects? Commented Mar 4, 2021 at 18:10
  • Look at the top answer to the question I referenced, it explains why you can't call methods on primitives and even gives an alternative. Commented Mar 4, 2021 at 18:13
  • There is an error: " The logging tag can be at most 23 characters, was 86 (getReactApplicationContext().checkCallingOrSelfPermission(Manifest.permission.READ_SMS)" Commented Mar 4, 2021 at 19:00
  • 1
    stackoverflow.com/questions/28168622/… Commented Mar 4, 2021 at 19:01

1 Answer 1

1

Because Build.VERSION.SDK_INT and other are integers. They are primitives and do not have toString() function. If you want to convert int to String you can use String.valueOf().

Log.i("Build.VERSION.SDK_INT", String.valueOf(Build.VERSION.SDK_INT));

Or sometimes it is easier to use string concatenation. For example:

Log.i("Build.VERSION.SDK_INT", "" + Build.VERSION.SDK_INT);

I mostly use second method for debugging purposes.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.