android - 错误:无效的方法声明;android 所需的返回类型
问题描述
我有一些麻烦这些代码。我想在蓝牙设备之间发送消息。但是 sendReceiver 函数有一些错误。Erorline 实际上是这样的:
public sendReceive (BluetoothSocket socket){
bluetoothSocket=socket;
InputStream tempIn =null;
OutputStream tempOut=null;
try {
tempIn=bluetoothSocket.getInputStream();
tempOut=bluetoothSocket.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
}
我的问题是:错误:方法声明无效;需要返回类型
我看起来都是同一个问题。但是没有任何答案。
以及关于 sendreceive 的所有功能。
private class SendReceive extends Thread{
private final BluetoothSocket bluetoothSocket;
private final InputStream inputStream;
private final OutputStream outputStream;
public sendReceive (BluetoothSocket socket){
bluetoothSocket=socket;
InputStream tempIn =null;
OutputStream tempOut=null;
try {
tempIn=bluetoothSocket.getInputStream();
tempOut=bluetoothSocket.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
}
public void run(){
byte[] buffer=new byte[1024];
int bytes;
while(true){
try {
bytes=inputStream.read(buffer);
handler.obtainMessage(STATE_MESSAGE_RECEIVER,bytes,-1,buffer).sendToTarget();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void write(byte[] bytes){
try {
outputStream.write(bytes);
} catch (IOException e) {
e.printStackTrace();
}
}
}
解决方案
您的构造函数名称不正确。而不是sendReceive
使用SendReceive
.
由于您已将InputStream inputStream
&声明OutputStream outputStream
为final
,因此请在构造函数中初始化它们或删除final
。如果您在类级别不需要它们,那么只需删除它们并在方法级别使用它。
推荐阅读
- python - 从 .views 文件启动新进程时,Flask 应用程序中的 RuntimeError “freeze_support”
- angular - 具有未知数量的通用属性的 Typescript 接口,所有这些属性都应输入为布尔值
- java - Java 方法接受不同的功能接口类型 - 可能吗?
- c# - 通过 REST api 在 Netsuite 中创建/更新联系人角色
- javascript - 从一组用户输入生成单词匹配
- java - Vaadin 对象不是声明类的实例
- c - (void) vs void 作为 C 中函数的返回类型
- mysql - MySQL合并两个ID相同的表
- unix - 为什么命令在 VFsync 和 Webminal 中不起作用?
- r - 如何在 SUDAAN 比较调查的估计值和该调查的样本)