I'm setting up a logger in a program but used some code from another program. I could fix all errors except for an incompatible type error returned by a Collectors.toList().
The error: https://i.sstatic.net/VtOsx.png
The return I get: https://i.sstatic.net/XGsvU.png
The return I need: https://i.sstatic.net/uMdXA.png
The list should return a string array but only returns an object array at this point. I can't cast it as a string array nor can I change the mLines array to an object array since that will cause problems later on in the code.
The code behind these function are native java so changing this changes it everywhere on my computer. Any idea how to fix this?
private static class LogcatAdapter extends BaseAdapter {
private List<String> mLines = Collections.emptyList();
void reload() {
try {
Process process = Runtime.getRuntime().exec("logcat -d -t 500 -v time");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
mLines = reader.lines().collect(Collectors.toList());
} catch (IOException e) {
StringWriter str = new StringWriter();
e.printStackTrace(new PrintWriter(str));
mLines = Collections.singletonList(str.toString());
}
notifyDataSetChanged();
}
@Override
public String toString() {
return BuildConfig.APPLICATION_ID + " " + BuildConfig.VERSION_NAME + "\n" +
mLines.stream().collect(Collectors.joining("\n"));
}
@Override
public int getCount() {
return mLines.size();
}
@Override
public String getItem(int position) {
return mLines.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_logline, parent, false);
}
String line = getItem(position);
((TextView) view.findViewById(R.id.text)).setText(line);
return view;
}
}