usb-serial-for-android icon indicating copy to clipboard operation
usb-serial-for-android copied to clipboard

UsbManager does not have a companion object issue

Open ImBerkayKaplan opened this issue 2 years ago • 0 comments

I followed your tutorial, but I'm having issues with UsbManager in Kotlin and Android Studio Java. When I use the command val manager: UsbManager = (UsbManager) getSystemService(Context.USB_SERVICE), the (UsbManager) spits out an error, sayin Classifier 'UsbManager' does not have a companion object, and thus must be initialized here. I Googled this, and saw a couple people having the similar issues, but theirs don't apply to mine. Do you have any recommendation?

I also tried val manager: UsbManager = getSystemService(Context.USB_SERVICE) as UsbManager just like the tutorial on https://developer.android.com/guide/topics/connectivity/usb/host, but no avail. This time, it's a different function that requires additional parameters. If the params are wrong, it will return null.

The line val manager: UsbManager = context.getSystemService(USB_SERVICE) as UsbManager works without errors, but the moment I go the page where I open the USB port, my application crashes because it returns null.

ImBerkayKaplan avatar Mar 24 '22 02:03 ImBerkayKaplan