-1

我正在一个程序中设置一个记录器,但使用了另一个程序中的一些代码。除了由 Collectors.toList() 返回的不兼容类型错误之外,我可以修复所有错误。

错误: 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;
        }

    }
4

1 回答 1

0

您可以“手动”指定调用的TtoList

mLines = reader.lines().collect(Collectors.<String>toList());

但这不应该是必要的。这似乎是 IntelliJ 中的一个错误,代码实际上可以编译并运行良好。

于 2019-04-01T11:44:24.857 回答