我想在我的项目中使用蓝牙打印机,但我收到了这个错误
lateinit property mmDevice has been not initialized
这是我的代码
lateinit var device:String
lateinit var mBluetoothAdapter: BluetoothAdapter
lateinit var mmSocket: BluetoothSocket
lateinit var mmDevice: BluetoothDevice
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_penjualan_cetak)
device = Function().getShared("printer","",this)
try {
findBT()
} catch (e: Exception) {
}
}
fun findBT(){
try{
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
val paireddevice = mBluetoothAdapter.bondedDevices
if(paireddevice.size > 0){
ePrinter.setText("Printer Belum Dipilih")
for (device:BluetoothDevice in paireddevice) {
if (device.name == this.device) {
// this is the error come from
mmDevice = device
break
}
}
}
}catch (e:Exception){
e.printStackTrace()
}
}
如何在 koltin 中初始化蓝牙设备?,我尝试了一些解决方案,但它不起作用