grundid / nfctools-examples

Examples for the nfctools library
68 stars 54 forks source link

NDef Reader and Writer Demos Fail with the Following Stack Trace: #2

Open brennydoogles opened 11 years ago

brennydoogles commented 11 years ago
Exception in thread "Thread-0" java.lang.RuntimeException:     java.lang.IllegalArgumentException: keyConfig cannot be null
    at org.nfctools.spi.acs.PollingCardScanner.run(PollingCardScanner.java:51)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.IllegalArgumentException: keyConfig cannot be null
    at org.nfctools.mf.mad.AbstractMad.<init>(AbstractMad.java:52)
    at org.nfctools.mf.mad.Mad1.<init>(Mad1.java:34)
    at org.nfctools.mf.mad.MadUtils.createApplicationDirectory(MadUtils.java:127)
    at org.nfctools.mf.ndef.MfNdefWriter.writeNdefMessage(MfNdefWriter.java:101)
    at org.nfctools.mf.ndef.MfNdefWriter.writeNdefMessage(MfNdefWriter.java:92)
    at     org.nfctools.examples.ndefwriter.NdefWriterDemo.cardDetected(NdefWriterDemo.java:52)
    at org.nfctools.spi.acs.PollingCardScanner.waitForCard(PollingCardScanner.java:61)
    at org.nfctools.spi.acs.PollingCardScanner.run(PollingCardScanner.java:45)
    ... 1 more
deibeeed commented 9 years ago

i'm getting the same error. when i traced the code, the Line states that "Mad1 mad1 = new Mad1(null, null);"

which is Mad1 extends AbstractMad and AbstractMad has this constructor.

public AbstractMad(MfClassicReaderWriter readerWriter, MadKeyConfig keyConfig) { if (keyConfig == null) throw new IllegalArgumentException("keyConfig cannot be null"); this.readerWriter = readerWriter; this.keyConfig = keyConfig; this.memoryLayout = readerWriter.getMemoryLayout(); }

so, if when you run NdefReaderDemo and NdefWriter demo, they will really throw you to that exception.

i dont really know the work around here i just traced the code and i can say that NdefReader and NdefWriter Demos will not work how many times you will try.

is there a way to make this work @grundid ?

UnknownJoe796 commented 6 years ago

I know this is many years late, but for others banging their head against the wall: It's a deprecated API. The new API usage looks like this (in Kotlin):

val adapter = NfcAdapter(getAvailableTerminal(), TerminalMode.INITIATOR, object : TagScannerListener{
    override fun onScanningEnded() {
        println("onScanningEnded")
    }

    override fun onScanningFailed(throwable: Throwable?) {
        println("onScanningFailed")
    }

    override fun onTagHandingFailed(throwable: Throwable?) {
        println("onTagHandingFailed")
    }
})
adapter.registerTagListener(MfClassicNfcTagListener(object : NdefOperationsListener{
    override fun onNdefOperations(ndefOperations: NdefOperations) {
        val records = ndefOperations.readNdefMessage()
        for(record in records){
            println("Record found: " + record.toString())
        }
    }
}))
SuneethaYamani commented 5 years ago
TagScannerListener

Thank you this solution solved my problem