gpt4 book ai didi

android - BufferedReader 的错误使用

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:06:54 34 4
gpt4 key购买 nike

s=new Scanner(new BufferedReader(new InputStreamReader(this.clientSocket.getInputStream())));

while(s.hasNext()){
System.out.println("Am intrat in bucla s:");
longitude=Integer.parseInt(s.next());
System.out.println("Valoare longitudine:"+longitude);
latitude=Integer.parseInt(s.next());
System.out.println(latitude);

我正在使用上面的行从客户端-服务器连接读取一些数据;这是服务器端。数据是在扫描仪中读取的,之后我尝试显示它,但是当我查看 logcat 时,我除了这个异常(exception)没有任何显示:

04-18 00:07:56.138: INFO/global(295): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.

我的客户端和服务器都在 android 上!有人知道我做错了什么吗?

这就是我读取数据的方式,我发送纬度和经度,我假设是用空格分隔的,奇怪的是有时会起作用:

        Cursor c=db.getAllData();

if(c.moveToFirst())
{
do{

longitude=Integer.parseInt(c.getString(1));
out.println(longitude);
latitude=Integer.parseInt(c.getString(2));
out.println(latitude);

}while(c.moveToNext());

}

最佳答案

该消息似乎是针对 BufferedReader 构造的。

首先,我认为您没有做任何“错误”的事情,因为您是说代码按预期工作并且消息是“INFO”,而不是“ERROR”甚至“WARNING”。

其次,如果您查看 BufferedReader 构造函数,您将看到:

BufferedReader(Reader in, int size) Constructs a new BufferedReader, providing in with size characters of buffer.

http://developer.android.com/reference/java/io/BufferedReader.html

改用该构造函数,您将不会看到该消息。

顺便说一句,logcat 充满了输出,有些行比其他行更相关。


使用 Log.d 而不是 System.out.println()。关于 System.out:http://developer.android.com/guide/developing/tools/adb.html

Viewing stdout and stderr

By default, the Android system sends stdout and stderr (System.out and System.err) output to /dev/null. In processes that run the Dalvik VM, you can have the system write a copy of the output to the log file. In this case, the system writes the messages to the log using the log tags stdout and stderr, both with priority I.

To route the output in this way, you stop a running emulator/device instance and then use the shell command setprop to enable the redirection of output. Here's how you do it:

$ adb shell stop $ adb shell setprop log.redirect-stdio true $ adb shell start

The system retains this setting until you terminate the emulator/device instance. To use the setting as a default on the emulator/device instance, you can add an entry to /data/local.prop on the device.

关于android - BufferedReader 的错误使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5702787/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com