Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UsbManager does not have a companion object issue #425

Open
ImBerkayKaplan opened this issue Mar 24, 2022 · 0 comments
Open

UsbManager does not have a companion object issue #425

ImBerkayKaplan opened this issue Mar 24, 2022 · 0 comments

Comments

@ImBerkayKaplan
Copy link

ImBerkayKaplan commented Mar 24, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants