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
13 stars 0 forks source link

Star Printer throwing Null pointer exception on connecting #19

Open zaibniazinnowi opened 7 months ago

zaibniazinnowi commented 7 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 7 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 7 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 5 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 4 months ago

@Tatsuki-Yamamoto2731

        **val settings = StarConnectionSettings(interfaceType, identifier)

        Above line is causing null pointer exception
Tatsuki-Yamamoto2731 commented 4 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 4 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 4 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 weeks 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.