27

I'm a newbie learning java and nfc. Actually I really need some help about my homework "NFC programming". I try this tutorial http://open-nfc.org/wp/editions/sdk-edition/creating-a-java-example/ and I still get this error msg:

Start failed !
NfcException : Error while starting the NFC Manager - Caused by NFC error DRIVER
at org.opennfc.NfcManager.start(Unknown Source)
at org.opennfc.NfcManager.getInstance(Unknown Source)
at example.Example.main(Example.java:26)
Exception in thread "main" java.lang.IllegalStateException
at org.opennfc.NfcManager.stop(Unknown Source)
at example.Example.main(Example.java:36)

Actually, what I want to run is this example code by open-nfc

NfcManager mgt = NfcManager.getInstance(null);
try {
  System.out.println(mgt.getProperty("open_nfc.version"));
  System.out.println(mgt.getProperty("nfcc.firmware_version"));
} finally {
  try {
    mgt.stop();
  } catch(NfcException e) {
    System.out.println("Error :" + e.getMessage());
  }
}

I've already start the connection center, nfc simulator, and server porting. And I have a device QPROX QP3000, already connected to my PC. I'm using eclipse juno and windows 7.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
pricillia
  • 279
  • 1
  • 3
  • 3
  • So your plan is to interact your NFC reader with some tags? – ThomasRS Aug 10 '12 at 11:56
  • 1
    I suggest that you restructure your code so that each of the getProperty() calls are within their own try block with its own catches. Does the getInstance() also need a try block? Take a look at http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html concerning exceptions or this tutorial http://tutorials.jenkov.com/java-exception-handling/basic-try-catch-finally.html – Richard Chambers Aug 12 '12 at 16:13
  • 4
    @pricillia I would suggest you to try the https://github.com/grundid/nfctools, for you to get started https://github.com/grundid/nfctools-examples, it will be lot helpful. – cypronmaya Oct 04 '12 at 11:11
  • 1
    If you have a recent Android phone, it might have an NFC reader. Check out http://code.google.com/p/ndef-tools-for-android/ to get started – ThomasRS Feb 26 '13 at 10:20

3 Answers3

1

The line calling NfcManager.getInstance(null) fails. Are you sure that NfcManager.getInstance() requires a null pareameter?

After that, calling mgt.stop() fails again with an java.lang.IllegalStateException , maybe because it's not started.

Esteve
  • 1,789
  • 18
  • 23
0

I have found a great article here (http://code.tutsplus.com/tutorials/reading-nfc-tags-with-android--mobile-17278) through which i learned how to communicate and make payments via NFC chips. Go through this and i hope it will solve your problem.

Rajendra Khabiya
  • 1,990
  • 2
  • 22
  • 39
-1

The documentation for NfcManager http://developer.android.com/reference/android/nfc/NfcManager.html mentions calling getSystemService(NFC_SERVICE) to create the NfcManager. Also the answer to an earlier stack overflow question How to check whether NFC is enabled or not in android? gives a simple example code snippet. Hope this helps.

Community
  • 1
  • 1
pav
  • 226
  • 3
  • 7
  • Note that [link-only answers](http://meta.stackoverflow.com/tags/link-only-answers/info) are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference – kleopatra Jul 15 '15 at 07:57