Java 在遵循Android NFC教程/示例时,无法解析为类型错误
我正试图使用以下示例源代码将NFC功能添加到我的应用程序中: 然而,当我这样做时,我会得到几个“无法解析为a类型”的错误 有人有什么建议吗 附言 我有一种感觉,它源于这样一行:Java 在遵循Android NFC教程/示例时,无法解析为类型错误,java,android,eclipse,nfc,Java,Android,Eclipse,Nfc,我正试图使用以下示例源代码将NFC功能添加到我的应用程序中: 然而,当我这样做时,我会得到几个“无法解析为a类型”的错误 有人有什么建议吗 附言 我有一种感觉,它源于这样一行:import com.nfc.linked.record.parsednefrecord 但我不知道如何解决这个问题 错误: ParsedNdefRecord cannot be resolved to a type line 97 Java Problem title_scanned_tag cannot
import com.nfc.linked.record.parsednefrecord代码>
但我不知道如何解决这个问题
错误:
ParsedNdefRecord cannot be resolved to a type line 97 Java Problem
title_scanned_tag cannot be resolved or is not a field line 77 Java Problem
ParsedNdefRecord cannot be resolved to a type line 100 Java Problem
NdefMessageParser cannot be resolved line 97 Java Problem
The import com.nfc.linked.record cannot be resolved line 30 Java Problem
title cannot be resolved or is not a field line 51 Java Problem
list cannot be resolved or is not a field line 50 Java Problem
资料来源:
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Menu;
import android.graphics.BitmapFactory;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.content.Intent;
import android.app.PendingIntent;
import android.app.Notification;
import android.app.NotificationManager;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.nfc.linked.record.ParsedNdefRecord;
import java.util.List;
public class AppActivity extends Activity implements OnClickListener {
static final String TAG = "ViewTag";
static final int ACTIVITY_TIMEOUT_MS = 1 * 1000;
private TextView mTitle;
private LinearLayout mTagContent;
private Button b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTagContent = (LinearLayout) findViewById(R.id.list);
mTitle = (TextView) findViewById(R.id.title);
resolveIntent(getIntent());
b=(Button)findViewById(R.id.button1);
b.setOnClickListener(this);
}
void resolveIntent(Intent intent) {
String action = intent.getAction();
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) {
Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
NdefMessage[] msgs;
if (rawMsgs != null) {
msgs = new NdefMessage[rawMsgs.length];
for (int i = 0; i < rawMsgs.length; i++) {
msgs[i] = (NdefMessage) rawMsgs[i];
}
} else {
// Unknown tag type
byte[] empty = new byte[] {};
NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty);
NdefMessage msg = new NdefMessage(new NdefRecord[] {record});
msgs = new NdefMessage[] {msg};
}
setTitle(R.string.title_scanned_tag);
buildTagViews(msgs);
} else {
Log.e(TAG, "Unknown intent " + intent);
finish();
return;
}
}
void buildTagViews(NdefMessage[] msgs) {
if (msgs == null || msgs.length == 0) {
return;
}
LayoutInflater inflater = LayoutInflater.from(this);
LinearLayout content = mTagContent;
// Clear out any old views in the content area, for example if you scan
// two tags in a row.
content.removeAllViews();
// Parse the first message in the list
// Build views for all of the sub records
List<ParsedNdefRecord> records = NdefMessageParser.parse(msgs[0]);
final int size = records.size();
for (int i = 0; i < size; i++) {
ParsedNdefRecord record = records.get(i);
content.addView(record.getView(this, inflater, content, i));
inflater.inflate(R.layout.main, content, true);
}
}
@Override
public void onNewIntent(Intent intent) {
setIntent(intent);
resolveIntent(intent);
}
@Override
public void setTitle(CharSequence title) {
mTitle.setText(title);
}
@Override
public void onClick(View v) {
Intent intent = new Intent();
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification noti = new Notification.Builder(this)
.setTicker("Link Access Granted!")
.setContentTitle("Linking Manager")
.setContentText("Link Access Granted!")
.setSmallIcon(R.drawable.ic_stat_notify_template3)
.setContentIntent(pIntent).getNotification();
noti.flags=Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
}
}
导入android.app.Activity;
导入android.app.pendingent;
导入android.content.Context;
导入android.content.DialogInterface;
导入android.os.Bundle;
导入android.view.MenuInflater;
导入android.view.MenuItem;
导入android.view.view;
导入android.view.Menu;
导入android.graphics.BitmapFactory;
导入android.view.view.OnClickListener;
导入android.widget.Button;
导入android.content.Intent;
导入android.app.pendingent;
导入android.app.Notification;
导入android.app.NotificationManager;
导入android.nfc.NdefMessage;
导入android.nfc.NdefRecord;
导入android.nfc.NfcAdapter;
导入android.os.Bundle;
导入android.os.Parcelable;
导入android.util.Log;
导入android.view.LayoutInflater;
导入android.view.WindowManager;
导入android.widget.LinearLayout;
导入android.widget.TextView;
导入com.nfc.linked.record.parsedDefRecord;
导入java.util.List;
公共类AppActivity扩展活动实现OnClickListener{
静态最终字符串TAG=“ViewTag”;
静态最终整数活动超时时间=1*1000;
私有文本视图mTitle;
私人线路布局mTagContent;
专用按钮b;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTagContent=(LinearLayout)findViewById(R.id.list);
mTitle=(TextView)findViewById(R.id.title);
resolveIntent(getIntent());
b=(按钮)findViewById(R.id.button1);
b、 setOnClickListener(此);
}
无效解析意向(意向){
String action=intent.getAction();
if(NfcAdapter.ACTION_TAG_DISCOVERED.equals(ACTION)){
Parcelable[]rawMsgs=intent.getParcelableArrayExtra(NfcAdapter.EXTRA\u NDEF\u消息);
NdefMessage[]MSG;
if(rawMsgs!=null){
msgs=新的NdefMessage[rawMsgs.length];
对于(int i=0;i
看起来在您的库中找不到任何nfc记录。如果您使用的是eclipse,请确保该库包含在您的项目中,并且在java构建屏幕最右侧的选项卡中,该库是c