star-micronics / StarXpand-SDK-Android

StarXpand SDK for Android is a software development kit for supporting application development for Star Micronics devices.
https://star-m.jp/starxpandsdk-oml.html
Other
14 stars 2 forks source link

Star Printer throwing Null pointer exception on connecting #19

Open zaibniazinnowi opened 10 months ago

zaibniazinnowi commented 10 months ago

Description

On initializing Printers with following inforamtion

Interfactype MacAddress 001162332406 and name :MCP31 (STR-001) Interfactype MacAddress 001162332404 and name :MCP31 (STR-001)

SDK is throwing following exception while initializing Printer object Attempt to invoke interface method 'boolean com.starmicronics.stario10.rawport.c.a(com.starmicronics.stario10.InterfaceType, java.lang.String)

This exception is thrown for multiple printers all information is added above.

Your device where the bug occurs

Your printer

Additional context

This issue can be recovered only when we clear the app storage or reinstalling the app, discover printer and then its start printing.

bandit-ibayashi commented 10 months ago

@zaibniazinnowi The fact that clearing the storage space used by the app or reinstalling the app resolves the problem suggests that the problem is caused by the process of recalling stored values. But more information is needed for a more detailed investigation.

Could you please share your implementation code for the part that initialises the printer and for the part where this exception occurs?

zaibniazinnowi commented 10 months ago

Hi @bandit-ibayashi Here is the code snippet which is used to initialize printer

 suspend fun init() {
        kotlin.runCatching {
            logP("StarPrintBatchUtil::init()::${appPrinter.name}(${appPrinter.portName})")
            val identifier = appPrinter.portName
            val interfaceType = **getInterfaceType**(context, appPrinter.interfaceType)
            **val settings = StarConnectionSettings(interfaceType, identifier)
            starPrinter = StarPrinter(settings, context)**
            starPrinter!!.closeAsync().await()
            starPrinter!!.openAsync().await()
            isPrinterConnected = true
        }.onSuccess {
            logP("StarPrintBatchUtil::init()::${appPrinter.name}(${appPrinter.portName}): Star Printer Initialized Success")
            isPrinterConnected = true
        }.onFailure {
            if (it is StarIO10Exception) {
                FirebaseAnalytics.getInstance(context).logEvent(STAR_INIT_ERROR) {
                    param(PARAM_ERROR_CODE, it.errorCode.name)
                    param(PARAM_PRINTER_NAME, "${appPrinter.name}(${appPrinter.portName})")
                }
                Firebase.crashlytics.log("StarPrintBatchUtil::init()::${appPrinter.name}(${appPrinter.portName}):: init Failed: errorCode: ${it.errorCode.name}")
                Firebase.crashlytics.recordException(it)
                val errorInfo = PrinterErrorMessages.getStarMessageOnException(context, it)
                appPrinter.errorType = errorInfo.second
                appPrinter.errorMsg = errorInfo.first
                appPrinter.timeStampOfError = System.currentTimeMillis()
                printerDatabase.printerDao().updatePrinter(appPrinter)
                val logError =
                    "StarPrintBatchUtil::init()::${appPrinter.name}(${appPrinter.portName}): initialization Failed: ${it.errorCode.name}, ${it.localizedMessage}"
                logP(logError)
                logP("StarPrintBatchUtil::init()::${appPrinter.name}(${appPrinter.portName}): init Failed message added to db. errorInfo: $errorInfo")
            } else {
                logP("StarPrintBatchUtil::init()::${appPrinter.name}(${appPrinter.portName}): Star Printer initialization Failed: ${it.localizedMessage}")
            }
            isPrinterConnected = false
        }
    }

        private fun **getInterfaceType**(context: Context, interfaceType: String): InterfaceType {
        return if (interfaceType.equals(context.getString(R.string.title_interface_lan), true)) {
            InterfaceType.Lan
        } else if (interfaceType.equals(
                context.getString(R.string.title_interface_bluetooth),
                true
            )
        ) {
            InterfaceType.Bluetooth
        } else if (interfaceType.equals(context.getString(R.string.title_interface_usb), true)) {
            InterfaceType.Usb
        } else
            InterfaceType.Lan
    }
Tatsuki-Yamamoto2731 commented 7 months ago

@zaibniazinnowi Thank you for sharing your information. Sorry for asking again, can you identify which line of code will cause a null pointer exception?

zaibniazinnowi commented 7 months ago

@Tatsuki-Yamamoto2731

        **val settings = StarConnectionSettings(interfaceType, identifier)

        Above line is causing null pointer exception
Tatsuki-Yamamoto2731 commented 7 months ago

@zaibniazinnowi We are checking our library with your information, but we haven't identified the root cause yet. You have already provided the stack trace information "boolean com.starmicronics.stario10.rawport.c.a(com.starmicronics.stario10.InterfaceType、java.lang.String)", but could you please a full stack trace? It will be helpful for us. Thank you for your cooperation.

zaibniazinnowi commented 6 months ago

@Tatsuki-Yamamoto2731 Here is the stack trace Attempt to invoke interface method 'boolean com.starmicronics.stario10.rawport.c.a(com.starmicronics.stario10.InterfaceType, java.lang.String)' on a null object reference.

Tatsuki-Yamamoto2731 commented 6 months ago

@zaibniazinnowi Thank you very much. Is it possible to have all the lines before and after the stack trace as well?

zaibniazinnowi commented 3 months ago

@Tatsuki-Yamamoto2731
I have opened another issue with the link below [Logs file not generated] (https://github.com/star-micronics/StarXpand-SDK-Android/issues/26)

P.S: We need to resolve this issue at highest priority as it keeps popping again and again.

zaibniazinnowi commented 2 months ago

@Tatsuki-Yamamoto2731 Here is the use case

Coroutine 1: PrinterA.init() Coroutine 2: PrinterB.init() Coroutine 3: PrinterC.init()

Coroutine 1: Open failed. Coroutine 2: Open failed. Coroutine 3: Open failed.

below is the code to initialize printer in co-routines logP("StarPrintBatchUtil::init()::${appPrinter.name}(${appPrinter.portName})") val identifier = appPrinter.portName val interfaceType = getInterfaceType(context, appPrinter.interfaceType) val settings = StarConnectionSettings(interfaceType, identifier) starPrinter = StarPrinter(settings, context) starPrinter!!.closeAsync().await() starPrinter!!.openAsync().await() isPrinterConnected = true

Moreover, doing this [#9100 Data Timeout] (https://github.com/star-micronics/StarXpand-SDK-Android/issues/28#issuecomment-2306533786) would help to fix the above issue?

Tatsuki-Yamamoto2731 commented 2 months ago

@zaibniazinnowi It seems that you said "it (#9100 Data Timeout) works" in this comment, but is the problem still unresolved? If so, please state it in the issue #28.

I think this issue #19 should be discussed about the Null pointer exception problem. Is the Null pointer exception problem resolved?

zaibniazinnowi commented 2 months ago

@Tatsuki-Yamamoto2731 #28 is resolved by updating printer configuration.

I have added another comment related to Portal is not logging and here is the detail comment

Tatsuki-Yamamoto2731 commented 2 months ago

@zaibniazinnowi I commented on that issue in #28. If the Null pointer exception problem has been resolved, I would like to close this Issue #19. Please let us know your situation.

zaibniazinnowi commented 1 month ago

@Tatsuki-Yamamoto2731
I have noticed that it is in progress.