HeligPfleigh / react-native-thermal-receipt-printer

A RN library for thermal printer
175 stars 103 forks source link

Attempt to invoke interface metho 'void com.pinmi.react.printer.adapter.Printer Adapter.prinRawData(java.lang.String,com.facebook.react.bridge.Callback)' on a null object reference #163

Open aasuparekh1 opened 11 months ago

aasuparekh1 commented 11 months ago

**- This code are curranty running in my app.

*Code**

const [printers, setPrinters] = useState([]); const [currentPrinter, setCurrentPrinter] = useState();

useEffect(() => { BLEPrinter.init().then(()=> { BLEPrinter.getDeviceList().then(setPrinters); }); }, []);

_connectPrinter => (printer) => { //connect printer BLEPrinter.connectPrinter(printer.inner_mac_address).then( setCurrentPrinter, error => console.warn(error)) }

printTextTest = () => { currentPrinter && USBPrinter.printText("sample text\n"); }

printBillTest = () => { currentPrinter && USBPrinter.printBill("sample bill"); }

...

return (

{ this.state.printers.map(printer => ( _connectPrinter(printer)}> {`device_name: ${printer.device_name}, inner_mac_address: ${printer.inner_mac_address}`} )) } Print Text Print Bill Text

)

* Issue : Attempt to invoke interface metho 'void com.pinmi.react.printer.adapter.Printer Adapter.prinRawData(java.lang.String,com.facebook.react.bridge.Callback)' on a null object reference

Expected Behavior

Environment

  "dependencies": {
    "react": "18.2.0",
    "react-native": "0.73.0",
    "react-native-picker-select": "^9.0.0",
    "react-native-thermal-receipt-printer": "^1.2.0-rc.2"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "^0.73.18",
    "@react-native/eslint-config": "^0.73.1",
    "@react-native/metro-config": "^0.73.2",
    "@react-native/typescript-config": "^0.73.1",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  }
marceloch2 commented 11 months ago

@aasuparekh1 same error here, do you manage to find a solution? Cheers.

Hasham24 commented 8 months ago

@marceloch2 @aasuparekh1 Same issue does anyone got the solution?

marceloch2 commented 7 months ago

@Hasham24 @aasuparekh1 I'm using NetPrinter.printRawData(decodedReceipt), maybe not related but you have a typo. "prinRawData", so "prin" instead of "print"

I'm able to use this printRawData using a fork that I did, I can't remember right now what I did, but you can try just to see if works https://github.com/marceloch2/react-native-thermal-receipt-printer And RC version: "react-native": "0.73.6",