我在一個程序中設置一個記錄器,但使用了另一個程序中的一些代碼。我可以修復所有錯誤,除了收集器返回的不兼容類型錯誤。錯誤:https://i.imgur.com/ak5pCEb.png我得到的回報:https://i.imgur.com/Ox6aCjw.png我需要的回報:https://i.imgur.com/JlLNPvz.png該列表應返回一個字符串數組,但此時僅返回一個對象數組。我不能將其轉換為字符串數組,也不能將mLines數組更改為對象數組,因為這會導致代碼中以后出現問題。這些函數背后的代碼是本機java,因此更改此代碼會更改其計算機上的所有位置。任何想法如何解決這個問題?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; } }
1 回答

慕村9548890
TA貢獻1884條經驗 獲得超4個贊
您可以指定“手動”調用的:T
toList
mLines = reader.lines().collect(Collectors.<String>toList());
但這不應該是必要的。這似乎是IntelliJ中的一個錯誤,代碼實際上編譯并運行良好。
添加回答
舉報
0/150
提交
取消