我试着点击一个按钮来连接python 但它不运行,除了它只运行在主
这是运行连接的代码
public class link {
public static void main(String a[]) {
try {
Process p = Runtime.getRuntime().exec(
"python C:/Users/ASUS/Desktop/sendingCode/jaad/app/test.py");
Scanner in = new Scanner(new InputStreamReader(
p.getInputStream()));
String line = "";
while ((line = in.nextLine()) != null) {
// display each output line form python script
System.out.println(line);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
一旦我把以前的代码对按钮,它不会与我工作,我不知道为什么
recordBtn=(Button)findViewById(R.id.recordBtn);
recordBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Process p = Runtime.getRuntime().exec(
"python C:/Users/ASUS/Desktop/sendingCode/jaad/app/test.py");
Scanner in = new Scanner(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = in.nextLine()) != null) {
// display each output line form python script
System.out.println(line);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
});
目前没有回答
相关问题 更多 >
编程相关推荐