我已经为我的android手机制作了一个应用程序来通过Raspberry Pi控制机器人车。该代码有效,但现在我试图将应用移植到Android Wear应用。但是,当我尝试在Wear设备上运行应用程序时,它在启动时崩溃。从错误日志中,它来自SetOnClickListeners。我应该如何解决这些错误?提前致谢!setOnClickListener崩溃我的磨损应用程序
编辑:
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent event) {
if ((R.id.buttonForward == v.getId())) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
socketCommand("forward");
break;
case MotionEvent.ACTION_UP:
socketCommand("stop");
break;
}
}
else if ((R.id.buttonReverse == v.getId())) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
socketCommand("backwards");
break;
case MotionEvent.ACTION_UP:
socketCommand("stop");
break;
}
}
else if ((R.id.buttonRight == v.getId())) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
socketCommand("right");
break;
case MotionEvent.ACTION_UP:
socketCommand("stop");
break;
}
}
else if ((R.id.buttonLeft == v.getId())) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
socketCommand("left");
break;
case MotionEvent.ACTION_UP:
socketCommand("stop");
break;
}
}
return false;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.buttonConnect: {
System.out.println("ONCLICK CONNECT");
SocketConnect.connect();
break;
}
case R.id.buttonDisconnect: {
SocketConnect.closeConnection();
break;
}
}
}
在此先感谢:由logcat的是RuntimeExceptions和一个NullPointerException http://puu.sh/ctfF4/49f0abe2ef.png
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonConnect = (Button) findViewById(R.id.buttonConnect);
buttonConnect.setOnClickListener(this);
buttonDisconnect = (Button) findViewById(R.id.buttonDisconnect);
buttonDisconnect.setOnTouchListener(this);
buttonReverse = (Button) findViewById(R.id.buttonReverse);
buttonReverse.setOnTouchListener(this);
buttonLeft = (Button) findViewById(R.id.buttonLeft);
buttonLeft.setOnTouchListener(this);
buttonForward = (Button) findViewById(R.id.buttonForward);
buttonForward.setOnTouchListener(this);
buttonRight = (Button) findViewById(R.id.buttonRight);
buttonRight.setOnTouchListener(this);
}
不知道是否有用给出的错误!
请将完整的错误添加到您的问题 – Paul 2014-10-27 21:54:04
完成。 NullPointerException – Riekelt 2014-10-27 22:03:18