2012-08-10 35 views
25

我是一個新手學習java和nfc。其實我真的需要一些關於我的作業「NFC編程」的幫助。 我試試這個教程http://open-nfc.org/wp/editions/sdk-edition/creating-a-java-example/,我仍然收到此錯誤信息:如何使用java創建簡單的NFC程序?

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) 

其實,我想運行是開放式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()); 
    } 
} 

我已經開始連接此示例代碼中心,nfc模擬器和服務器端口。我有一臺QPROX QP3000,已連接到我的電腦。我正在使用eclipse juno和windows 7.

+0

所以你的計劃是與你的NFC閱讀器與一些標籤交互? – ThomasRS 2012-08-10 11:56:28

+1

我建議你重構你的代碼,以便每個getProperty()調用都在它們自己的catch塊內的try塊中。 getInstance()是否也需要try塊?看看http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html有關異常或本教程http://tutorials.jenkov.com/java-exception-handling/basic-try- catch-finally.html – 2012-08-12 16:13:07

+4

@pricillia我建議你嘗試https://github.com/grundid/nfctools,爲你開始https://github.com/grundid/nfctools-examples,它會很多很有幫助。 – cypronmaya 2012-10-04 11:11:16

回答

1

調用NfcManager.getInstance(null)的行失敗。 您確定NfcManager.getInstance()需要一個null副屏?

之後,致電mgt.stop()再次以java.lang.IllegalStateException 失敗,可能是因爲它沒有啓動。

-1

NfcManager http://developer.android.com/reference/android/nfc/NfcManager.html的文檔提到調用getSystemService(NFC_SERVICE)來創建NfcManager。還有一個早期的堆棧溢出問題How to check whether NFC is enabled or not in android?的答案給出了一個簡單的示例代碼片段。希望這可以幫助。

+0

請注意,[僅鏈接答案](http://meta.stackoverflow.com/tags/link-only -answers/info),所以SO答案應該是搜索解決方案的終點(而另一個引用的中途停留時間往往會隨着時間的推移而變得過時)。請考慮在此添加獨立的摘要,並將鏈接保留爲參考 – kleopatra 2015-07-15 07:57:22

相關問題