【发布时间】:2013-04-26 14:46:10
【问题描述】:
我正在关注一个关于 Android 中蓝牙的示例。当按照示例并尝试理解该过程时,我收到一个错误:“返回类型与 Thread.getState() 不兼容”。是什么导致了这个错误,我该如何解决?
以下是相关代码:
private int mState;
/**
* Set the current state of the chat connection
* @param state An integer defining the current connection state
*/
private synchronized void setState(int state) {
if (D) Log.d(TAG, "setState() " + mState + " -> " + state);
mState = state;
// Give the new state to the Handler so the UI Activity can update
mHandler.obtainMessage(Rc_auto.MESSAGE_STATE_CHANGE, state, -1).sendToTarget();
}
/**
* Return the current connection state. */
public synchronized int getState() {
return mState;
}
//How it's called
public synchronized void start() {
setState(STATE_LISTEN);
}
【问题讨论】:
-
在您当前的代码中,您应该返回一个
synchronized int,但您只返回一个int。删除synchronized。 -
什么是同步整数...?
synchronized适用于方法,而不适用于返回类型。 -
您是否有可能将
extends Thread添加到以前工作的类中?因为那时与Thread类中的method of the same name有冲突 -
我删除了扩展线程并且错误消失了 thx
标签: android