Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 正在等待调试程序解决。。。消息然后VM关闭_Android_Sockets_Ssl_Dalvik - Fatal编程技术网

Android 正在等待调试程序解决。。。消息然后VM关闭

Android 正在等待调试程序解决。。。消息然后VM关闭,android,sockets,ssl,dalvik,Android,Sockets,Ssl,Dalvik,我开始学习android编程。我正在尝试将android应用程序连接到支持SSL的服务器。我以这篇文章为例。如果出现错误,程序将以“不幸已停止”结束 这是我的代码: public class MainActivity extends ActionBarActivity { /* Called when the activity is first created. */ EditText iptxt; Button sendbtn; TextView logtxt; EditText port

我开始学习android编程。我正在尝试将android应用程序连接到支持SSL的服务器。我以这篇文章为例。如果出现错误,程序将以“不幸已停止”结束

这是我的代码:

public class MainActivity extends ActionBarActivity {

/* Called when the activity is first created. */

EditText iptxt;
Button sendbtn;
TextView logtxt;
EditText porttxt;
EditText cmdtxt;

// port to use
private String ip_address;
private int port = 1992;
private String cmdstr = null;
private SSLSocket socket = null;
private BufferedWriter out = null;
private BufferedReader in = null;
private final String TAG = "TAG";
private String keystorepass = "mypasswordisCOOL!";
private String keypassword = "mypasswordRULEZ@";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    iptxt = (EditText) findViewById(R.id.iptxt);
    porttxt = (EditText) findViewById(R.id.porttxt);
    cmdtxt = (EditText) findViewById(R.id.cmdtxt);

    logtxt = (TextView) findViewById(R.id.logtxt);

    sendbtn = (Button) findViewById(R.id.sendbtn);

    sendbtn.setClickable(true);
    sendbtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (iptxt.getText().toString().equals(null) || porttxt.getText().toString().equals(null)) {
                Toast.makeText(v.getContext(), "Please enter an IP address or Port number", Toast.LENGTH_LONG).show();
            } else {
               cmdstr = cmdtxt.getText().toString();
               if (cmdstr == null) {
                   Toast.makeText(v.getContext(), "No command was entered", Toast.LENGTH_LONG).show();
               }

                Log.i(TAG, "makes it to here");

                port = Integer.parseInt(porttxt.getText().toString());
                ip_address = iptxt.getText().toString();

                try {

                    KeyStore ks = KeyStore.getInstance("BKS");
                    InputStream key = v.getResources().openRawResource(R.raw.mykeyandroid);
                    ks.load(key,keystorepass.toCharArray());
                    SSLSocketFactory socketFactory = new SSLSocketFactory(ks);
                    socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
                    socket = (SSLSocket)
                            socketFactory.createSocket(new Socket(ip_address,port), ip_address, port, false);
                    socket.startHandshake();


                    out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
                    in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                    chat(cmdstr);

                    key.close();
                    in.close();
                    out.close();
                    socket.close();

                } catch (UnknownHostException e) {
                    Toast.makeText(v.getContext(), "Unknown host", Toast.LENGTH_SHORT).show();
                    Log.i(TAG, "Unknown host");
                    //System.exit(1);
                } catch (IOException e) {
                    Toast.makeText(v.getContext(), "No I/O", Toast.LENGTH_SHORT).show();
                    Log.i(TAG, "No I/O");
                    e.printStackTrace();
                    //System.exit(1);
                } catch (KeyStoreException e) {
                    Toast.makeText(v.getContext(), "Keystore ks error", Toast.LENGTH_SHORT).show();
                    Log.i(TAG, "Keystore ks error");
                    //System.exit(-1);
                } catch (NoSuchAlgorithmException e) {
                    Toast.makeText(v.getContext(), "No such algorithm for ks.load", Toast.LENGTH_SHORT).show();
                    Log.i(TAG, "No such algorithm for ks.load");
                    e.printStackTrace();
                    //System.exit(-1);
                } catch (CertificateException e) {
                    Toast.makeText(v.getContext(), "certificate missing", Toast.LENGTH_SHORT).show();
                    Log.i(TAG, "certificate missing");
                    e.printStackTrace();
                    //System.exit(-1);
                } catch (KeyManagementException e) {
                    Toast.makeText(v.getContext(), "KeyManagementException", Toast.LENGTH_SHORT).show();
                    Log.i(TAG, "key management exception");
                    e.printStackTrace();
                    //System.exit(-1);
                } catch (UnrecoverableKeyException e) {
                    Toast.makeText(v.getContext(), "UnrecoverableKeyException", Toast.LENGTH_SHORT).show();
                    Log.i(TAG,"unrecoverableKeyException");
                    e.printStackTrace();
                }


            }

        }
    });

}


public void chat(String temp){
    String message = temp;
    String line = "";
    // send id of the device to match with the image
    try {
        out.write(message);
        out.flush();
    } catch (IOException e2) {
        Log.i(TAG,"Read failed");
        System.exit(1);
    }
    // receive a ready command from the server
    try {
        line = in.readLine();
        logtxt.setText("SERVER SAID: " + line);

    } catch (IOException e1) {
        Log.i(TAG,"Read failed");
        System.exit(1);
    }
}
}
这是日志:

06-05 22:30:17.553      543-543/ru.nightvolks.nvclienttls.application D/dalvikvm﹕ Not late-enabling CheckJNI (already on)
06-05 22:30:17.874      543-543/ru.nightvolks.nvclienttls.application W/ActivityThread﹕ Application ru.nightvolks.nvclienttls.application is waiting for the debugger on port 8100...
06-05 22:30:17.903      543-543/ru.nightvolks.nvclienttls.application I/System.out﹕ Sending WAIT chunk
06-05 22:30:18.163      543-550/ru.nightvolks.nvclienttls.application I/dalvikvm﹕ Debugger is active
06-05 22:30:18.305      543-543/ru.nightvolks.nvclienttls.application I/System.out﹕ Debugger has connected
06-05 22:30:18.305      543-543/ru.nightvolks.nvclienttls.application I/System.out﹕ waiting for debugger to settle...
06-05 22:30:18.502      543-543/ru.nightvolks.nvclienttls.application I/System.out﹕ waiting for debugger to settle...
06-05 22:30:18.702      543-543/ru.nightvolks.nvclienttls.application I/System.out﹕ waiting for debugger to settle...
06-05 22:30:18.912      543-543/ru.nightvolks.nvclienttls.application I/System.out﹕ waiting for debugger to settle...
06-05 22:30:19.114      543-543/ru.nightvolks.nvclienttls.application I/System.out﹕ waiting for debugger to settle...
06-05 22:30:19.312      543-543/ru.nightvolks.nvclienttls.application I/System.out﹕ waiting for debugger to settle...
06-05 22:30:19.516      543-543/ru.nightvolks.nvclienttls.application I/System.out﹕ waiting for debugger to settle...
06-05 22:30:19.717      543-543/ru.nightvolks.nvclienttls.application I/System.out﹕ waiting for debugger to settle...
06-05 22:30:19.918      543-543/ru.nightvolks.nvclienttls.application I/System.out﹕ debugger has settled (1340)
06-05 22:30:21.642      543-543/ru.nightvolks.nvclienttls.application D/gralloc_goldfish﹕ Emulator without GPU emulation detected.
06-05 22:30:21.722      543-543/ru.nightvolks.nvclienttls.application W/TextLayoutCache﹕ computeValuesWithHarfbuzz -- need to force to single run
06-05 22:30:43.273      543-543/ru.nightvolks.nvclienttls.application I/TAG﹕ makes it to here
06-05 22:30:43.273      543-543/ru.nightvolks.nvclienttls.application D/AndroidRuntime﹕ Shutting down VM
06-05 22:30:43.282      543-543/ru.nightvolks.nvclienttls.application W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x409961f8)

服务器代码取自一篇文章。请帮助我更正错误。

可能的副本也。。。应用程序是否设置了可调试标志?看见应用程序是否具有
INTERNET
权限?看,等待调试器解决不是很有趣。例外情况是,但从上面包含的日志片段的最后一行开始。您需要识别异常以及它在哪一行失败。如果它不在日志中,那么它可能会在调试器中停止,您可以从那里获得信息。