Surile / react-native-sunmi-printer

商米内置打印机
MIT License
44 stars 28 forks source link

V2s - Invoke interface method on a null object reference #43

Closed d-lindau closed 6 months ago

d-lindau commented 6 months ago

241074767-803c134f-cdd5-41d4-9cd1-cd3f457033d1

Sunmi V2s react-native-cli: 2.0.1 react-native: 0.71.14 node 20 (also tried node 18) windows 11 buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33

I have now started a brand new project. I have only installed @heasy/react-native-sunmi-printer and changed App.tsx to this:


import React from 'react';
import { SafeAreaView, Button } from 'react-native';
import SunmiPrinter from '@heasy/react-native-sunmi-printer';

async function _printRecieve(text) {
  if (text === "print") {
    alert("Printing");
    try {
      await SunmiPrinter.printerText('Hello World\n');
    } catch (e) {
      // Handle the error here. Using `setState` implies this should be within a class or useState hook
      console.error("Printer error: " + e.message);
    }
  }
}

function App(): JSX.Element {
  const handlePrint = () => _printRecieve('print'); // This creates a new function that calls _printRecieve with 'print'

  return (
    <SafeAreaView>
      <Button title="Print" onPress={handlePrint} />
    </SafeAreaView>
  );
}

export default App;

I get the error on start.

Works without issues on V2. But fails with the error shown in the image on V2s.

d-lindau commented 6 months ago

On my other computer i started a brand new react-native project. Got the exact same result: react-native-cli: 2.0.1 react-native: 0.73.2 buildToolsVersion = "34.0.0" minSdkVersion = 21 compileSdkVersion = 34 targetSdkVersion = 34 ndkVersion = "25.1.8937393" kotlinVersion = "1.8.0"

d-lindau commented 6 months ago

This solved it: https://github.com/Surile/react-native-sunmi-printer/issues/22#issuecomment-1314951226