BufferedReader中的错误用法 [英] wrong usage of BufferedReader

查看:134
本文介绍了BufferedReader中的错误用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  S =新的扫描仪(新的BufferedReader(新的InputStreamReader(this.clientSocket.getInputStream())));        而(s.hasNext()){
             的System.out.println(AM intrat在bucla s:时);
             经度=的Integer.parseInt(s.next());
             的System.out.println(Valoare longitudine:+经度);
             纬度=的Integer.parseInt(s.next());
             的System.out.println(纬度);

我在上面使用的线条来读取客户端 - 服务器连接的一些数据,这是服务器一面。数据扫描器S读取之后,我尝试以显示它,但是当我在看我logcat中什么都没有显示,但此异常:


  

04-18 00:07:56.138:信息/全球(295):
  在使用默认的缓冲区大小
  BufferedReader类的构造函数。它会
  是更好的是明确的,如果一个8K-CHAR
  缓冲器是必需的。


我的两个客户端和服务器上的Andr​​oid!没有人有任何知道我做错了吗?

这是我如何读取数据,我送纬度和经度,我认为是分隔的空格,奇怪的是,有时是工作:

 光标C = db.getAllData();           如果(c.moveToFirst())
             {
              做{                  经度=的Integer.parseInt(c.getString(1));
                  通过out.println(经度);
                  纬度=的Integer.parseInt(c.getString(2));
                  通过out.println(纬度);              }而(c.moveToNext());             }


解决方案

该消息似乎是在的BufferedReader 结构。

首先,我不认为你正在做什么错误的,因为你是说,code将按预期,消息是INFO,而不是错误,甚至警告。

第二,如果你看看的BufferedReader 构造,您将看到:


  

的BufferedReader(读者,INT大小)
  构造一个新的BufferedReader,提供与缓冲区的大小字符。


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

使用该构造函数,而不是你不应该看到的消息。

顺便说一句,在的logcat 是全力输出,部分线路比其他人更重要。


使用 Log.d 而不是的System.out.println()。关于的System.out HTTP ://developer.android.com/guide/developing/tool​​s/adb.html


  

查看输出和错误


  
  

默认情况下,Android系统发送
  stdout和stderr(System.out和
  System.err的)输出到/ dev / null的。在
  运行在Dalvik虚拟机进程,您
  可以让系统编写的副本
  输出到日志文件中。在这
  情况下,系统写入的消息
  使用日志标签标准输出日志
  和标准错误,都与我优先


  
  

要路线以这种方式输出,则
  停止正在运行的模拟器/设备
  实例,然后使用shell
  命令setprop使
  输出重定向。这里是你如何
  做到这一点:


  
  

$亚行外壳停止$亚行外壳setprop
  log.redirect-标准输入输出真正的$ ADB壳
  启动


  
  

系统保留此设置,直到
  你终止模拟器/设备
  实例。要使用设置为
  默认情况下,模拟器/设备上
  例如,你可以添加一个条目
  /data/local.prop设备上。


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);

I'm using the lines above to read some data from a client-server connection;this is the server side.The data are read in scanner s and after that I try to display it,but when I look in logcat I have nothing display but this 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.

Both my client and server are on android!Does anyone have any idea what I'm doing wrong?

This is how I read the data,I send latitude and longitude,I assume that is blank spaces delimited,the strange thing is that sometimes is working:

        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());

             }

解决方案

The message seems to be for the BufferedReader construct.

First, I do not think you are doing anything "wrong", since you are saying that the code works as expected and the message is "INFO", not "ERROR" or even "WARNING".

Second, if you look at the BufferedReader constructor, you will see:

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

Use that constructor instead and you should not see that message.

BTW, the logcat is full of output, some lines are more relevant than others.


Use Log.d instead of System.out.println(). Regarding 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.

这篇关于BufferedReader中的错误用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆