I would like to log raw data like arrays in my logcat, so I know what is the output.
Lets say I have an array… like that:
File[] mp3List = ...
Log.v("test", mp3List);
Why can’t I just log the array to console? How can I do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The reason why this doesn’t work is simply because the 2nd argument of
Log.vis aStringnot aFile[]. Java strictly enforces argument types.Update:
You can easily transform the information contained a
Fileobject into aStringobject. All java objects implement atoString(), which if I remember correctly returns a combination of theClassNameand theaddressof the object is located. However this usually doesn’t contain useful information. So you need to define the conversion yourself.Now to convert from
File[]toStringis more complicated because you when call a method on an array it works on the array object rather than on members of an array (which contains the information I suspect you care about). So callingmp3List.toString()will return a single string that describes the array object and not the information contained in the array.So you’ll probably want to write a method like this:
And then call make your log call as follows:
However this might be hard to read.
I personally would do it like this:
Its simpler, produces cleaner log messages and is easier to understand what is going on as a programmer.