开发者

wrong usage of BufferedReader

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 latitud开发者_开发问答e 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.


Is your data white-space delimited? If not, you will need to specify delimiter for your Scanner.

Do you have some exception handling code you are not showing... e.g. hiding a NumberFormatException if parseInt failed?

While you debug this issue (unless you can attach a debugger), you could log messages at points like when you accept new client connection and when you enter and exit your worker thread. This might help you see whether you are getting as far as scanning the data when you think you are receiving.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜