0

telnet ソケット入力から「アーティスト - タイトル」を解析したいと考えています。現在、最後の行「END」のみを表示しています。私は何を間違っていますか?java.plsヘルプの初心者です...

仕事に私の活動スクリプト:

try {
        Socket s = new Socket("10.0.2.2", 5555);


        BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream(), "ISO8859_1"));



        String on_air = "request.on_air" + System.getProperty("line.separator");
        out.write(on_air);
        out.flush();
        Log.i("TcpClient", "sent: " + on_air);
        String on_airin = in.readLine() + System.getProperty("line.separator");
        Log.i("TcpClient", "received: " + on_airin);
        String metadata = "ao.metadata "+ on_airin + System.getProperty("line.separator"); 
        out.write(metadata);
        out.flush();
        Log.i("TcpClient", "sent2: " + metadata);
        String metadatain = in.readLine() + System.getProperty("line.separator");
        Log.i("TcpClient", "received: " + metadatain);

        String line = in.readLine();
        while (line != null) {

            line = in.readLine();


            System.out.println(line);
            output = (TextView) findViewById(R.id.textView2);
            output.setText(line);





//tv.setText(online + formatedDate );
        output = (TextView) findViewById(R.id.textView1);



s.close();

    }} catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

私のSystem.out.println http://pastebin.com/SkfiPXar

4

2 に答える 2

1

readLine()印刷前に追加の作業を行います。次の 3 行を折りたたみます。

String line = in.readLine();
while (line != null) {
    line = in.readLine();

の中へ

String line = null;
while ((line = in.readLine()) != null) {  

また、ループSocket内を閉じているように見えるため、問題が発生する可能性があります。while

于 2012-10-30T14:23:29.930 に答える
0

フル アクティビティ:

public class MainActivity extends Activity {


//TextView output; //textview to display the artist
TextView artist;
//TextView output; //textview to display the duration
TextView time;
/** Called when the activity is first created. */



public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);






    try {
        Socket s = new Socket("10.0.2.2", 5555);


        BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream(), "ISO8859_1"));

        //get audio estimated remaining time
        String milliseconds = "ao.remaining" + System.getProperty("line.separator");
        out.write(milliseconds);
        out.flush();
        Log.i("TcpClient", "sent: " + milliseconds);
        String milliseconds_in = in.readLine() + System.getProperty("line.separator");
        Log.i("TcpClient", "received: " + milliseconds_in);



        //get metadata stuff  
        String on_air = "request.on_air" + System.getProperty("line.separator");
        out.write(on_air);
        out.flush();
        Log.i("TcpClient", "sent: " + on_air);
        String on_airin = in.readLine() + System.getProperty("line.separator");
        Log.i("TcpClient", "received: " + on_airin);
        String metadata = "ao.metadata "+ on_airin + System.getProperty("line.separator"); 
        out.write(metadata);
        out.flush();
        Log.i("TcpClient", "sent: " + metadata);
        String metadatain = in.readLine() + System.getProperty("line.separator");
        Log.i("TcpClient", "received: " + metadatain);






        String closetelnet = "exit" + System.getProperty("line.separator"); 
        out.write(closetelnet);
        out.flush();
        Log.i("TcpClient", "sent: " + closetelnet);
        String closetelnetin = in.readLine() + System.getProperty("line.separator");
        Log.i("TcpClient", "received: " + closetelnetin);


        String line = null;
        while ((line = in.readLine()) != null) {


            System.out.println(line);
            artist = (TextView) findViewById(R.id.textView2);
            artist.setText(line);

            float seconds = Float.parseFloat(milliseconds_in);
            Date date = new Date((long)(seconds * 1000));
            SimpleDateFormat formater = new SimpleDateFormat("mm:ss");
            String formatedDate = formater.format(date);
            //android.util.Log.d("This will display:", formatedDate);

            time = (TextView) findViewById(R.id.textView1);
            time.setText(formatedDate);


    }   
        s.close();

    }catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

}

System.out http://pastebin.com/G1P1HrvA

于 2012-10-30T16:14:46.147 に答える