我意识到关于这个主题有很多问题,但是我已经在stackoverflow和google上搜索了关于这个问题的每篇文章,但仍无法解决我的问题。
所以基本上我正在尝试创建一个应用程序,在我出国留学的同时,为个别项目使用NFC技术。我现在的第一个任务是简单地阅读和写入NFC标签。出国留学只是相关的,因为这会使语言障碍变得更加困难,因为这里有人帮助。
我尝试链接的第一个活动是TagsActivity。这没用,所以我想我会创建另一个简单的活动试图链接到,这就是ToTag。都没有奏效。两者都已在Manifest文件中,这似乎是对我的许多类似问题的修复。
我已经被困在同一个问题好几天了,现在我花了一个多小时才终于解决了R.java问题,但是在确定这个问题仍然存在之后。
我要发布几乎所有相关的代码,因为我真的很难过为什么它不起作用。
MainActivity
package com.example.myapp;
import java.util.ArrayList;
import java.util.List;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
public class TagsActivity extends Activity {
private Button mEnableWriteButton;
private EditText mTextField;
private NfcAdapter mNfcAdapter;
private ProgressBar mProgressBar;
private boolean isWriteReady = false;
private static final String MIME_TYPE = "application/com.myapp.nfc.tag";
public void processWriteIntent(Intent intent){
if(isWriteReady && NfcAdapter.ACTION_TAG_DISCOVERED.equals(getIntent().getAction())){
Tag detectedTag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);
String tagWriteMessage = mTextField.getText().toString();
byte[] payload = new String(tagWriteMessage).getBytes();
if(detectedTag != null && NfcUtils.writeTag(
NfcUtils.createMessage(MIME_TYPE, payload), detectedTag)) {
Toast.makeText(this, "Wrote '" + tagWriteMessage + "' to a tag!",
Toast.LENGTH_LONG).show();
setTagWriteReady(false);
}
else{
Toast.makeText(this, "Write failed. Please try again.", Toast.LENGTH_LONG).show();
}
}
}
public void processReadIntent(Intent intent){
List<NdefMessage> intentMessages = NfcUtils.getMessagesFromIntent(intent);
List<String> payloadStrings = new ArrayList<String>(intentMessages.size());
for(NdefMessage message : intentMessages){
for(NdefRecord record : message.getRecords()){
byte[] payload = record.getPayload();
String payloadString = new String(payload);
if(!TextUtils.isEmpty(payloadString)){
payloadStrings.add(payloadString);
}
}
}
if(!payloadStrings.isEmpty()){
Toast.makeText(TagsActivity.this, "Read from tag: " +
TextUtils.join(",", payloadStrings), Toast.LENGTH_LONG);
}
}
/**
* This method enables this activity to write a tag
*
* @param isWriteReady
*
*/
public void setTagWriteReady(boolean isWriteReady){
this.isWriteReady = isWriteReady;
if(isWriteReady){
IntentFilter[] writeTagFilters = new IntentFilter[] {
new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED) };
mNfcAdapter.enableForegroundDispatch(TagsActivity.this, NfcUtils.getPendingIntent(TagsActivity.this),
writeTagFilters, null);
}
else {
//Disable dispatch if not writing tags
mNfcAdapter.disableForegroundDispatch(TagsActivity.this);
}
}
@Override
public void onNewIntent(Intent intent){
//onResume gets called after this to handle the intent
setIntent(intent);
}
@Override
public void onResume(){
super.onResume();
if(isWriteReady && NfcAdapter.ACTION_TAG_DISCOVERED.equals(getIntent().getAction())){
processWriteIntent(getIntent());
}
else if(!isWriteReady &&
(NfcAdapter.ACTION_TAG_DISCOVERED.equals(
getIntent().getAction())
|| NfcAdapter.ACTION_NDEF_DISCOVERED.equals(
getIntent().getAction() ))) {
processReadIntent(getIntent());
}
}
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tags);
/*Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView); */
//Make sure we're running on Honeycomb or higher to use ActionBar
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
//Show the Up button in the action bar
getActionBar().setDisplayHomeAsUpEnabled(true);
}
mTextField = (EditText) findViewById(R.id.progress_bar);
mProgressBar = (ProgressBar) findViewById(R.id.edit_message);
mProgressBar.setVisibility(View.GONE);
mEnableWriteButton = (Button) findViewById(R.id.enable_write_button);
mEnableWriteButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
setTagWriteReady(!isWriteReady);
mProgressBar.setVisibility(isWriteReady ? View.VISIBLE : View.GONE);
}
});
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
if(mNfcAdapter == null){
Toast.makeText(this, "Sorry, NFC not available on this device", Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.tags, menu);
return true;
}
}
TagsActivity
package com.example.myapp;
import java.util.ArrayList;
import java.util.List;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
public class TagsActivity extends Activity {
private Button mEnableWriteButton;
private EditText mTextField;
private NfcAdapter mNfcAdapter;
private ProgressBar mProgressBar;
private boolean isWriteReady = false;
private static final String MIME_TYPE = "application/com.myapp.nfc.tag";
public void processWriteIntent(Intent intent){
if(isWriteReady && NfcAdapter.ACTION_TAG_DISCOVERED.equals(getIntent().getAction())){
Tag detectedTag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);
String tagWriteMessage = mTextField.getText().toString();
byte[] payload = new String(tagWriteMessage).getBytes();
if(detectedTag != null && NfcUtils.writeTag(
NfcUtils.createMessage(MIME_TYPE, payload), detectedTag)) {
Toast.makeText(this, "Wrote '" + tagWriteMessage + "' to a tag!",
Toast.LENGTH_LONG).show();
setTagWriteReady(false);
}
else{
Toast.makeText(this, "Write failed. Please try again.", Toast.LENGTH_LONG).show();
}
}
}
public void processReadIntent(Intent intent){
List<NdefMessage> intentMessages = NfcUtils.getMessagesFromIntent(intent);
List<String> payloadStrings = new ArrayList<String>(intentMessages.size());
for(NdefMessage message : intentMessages){
for(NdefRecord record : message.getRecords()){
byte[] payload = record.getPayload();
String payloadString = new String(payload);
if(!TextUtils.isEmpty(payloadString)){
payloadStrings.add(payloadString);
}
}
}
if(!payloadStrings.isEmpty()){
Toast.makeText(TagsActivity.this, "Read from tag: " +
TextUtils.join(",", payloadStrings), Toast.LENGTH_LONG);
}
}
/**
* This method enables this activity to write a tag
*
* @param isWriteReady
*
*/
public void setTagWriteReady(boolean isWriteReady){
this.isWriteReady = isWriteReady;
if(isWriteReady){
IntentFilter[] writeTagFilters = new IntentFilter[] {
new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED) };
mNfcAdapter.enableForegroundDispatch(TagsActivity.this, NfcUtils.getPendingIntent(TagsActivity.this),
writeTagFilters, null);
}
else {
//Disable dispatch if not writing tags
mNfcAdapter.disableForegroundDispatch(TagsActivity.this);
}
}
@Override
public void onNewIntent(Intent intent){
//onResume gets called after this to handle the intent
setIntent(intent);
}
@Override
public void onResume(){
super.onResume();
if(isWriteReady && NfcAdapter.ACTION_TAG_DISCOVERED.equals(getIntent().getAction())){
processWriteIntent(getIntent());
}
else if(!isWriteReady &&
(NfcAdapter.ACTION_TAG_DISCOVERED.equals(
getIntent().getAction())
|| NfcAdapter.ACTION_NDEF_DISCOVERED.equals(
getIntent().getAction() ))) {
processReadIntent(getIntent());
}
}
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tags);
/*Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView); */
//Make sure we're running on Honeycomb or higher to use ActionBar
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
//Show the Up button in the action bar
getActionBar().setDisplayHomeAsUpEnabled(true);
}
mTextField = (EditText) findViewById(R.id.progress_bar);
mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
mProgressBar.setVisibility(View.GONE);
mEnableWriteButton = (Button) findViewById(R.id.enable_write_button);
mEnableWriteButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
setTagWriteReady(!isWriteReady);
mProgressBar.setVisibility(isWriteReady ? View.VISIBLE : View.GONE);
}
});
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
if(mNfcAdapter == null){
Toast.makeText(this, "Sorry, NFC not available on this device", Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.tags, menu);
return true;
}
}
ToTag
package com.example.myapp;
import android.app.Activity;
import android.os.Bundle;
public class ToTag extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_to_tag);
// TODO Auto-generated method stub
}
}
MyApp清单
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.myapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.myapp.TagsActivity"
android:label="@string/title_activity_tags"
android:launchMode="singleTop"
android:parentActivityName="com.example.myapp.MainActivity" >
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/com.example.myapp" />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myapp.MainActivity" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/com.example.myapp" />
</intent-filter>
</activity>
<activity
android:name="com.example.myapp.ToTagActivity"
android:label="@string/title_activity_to_tag"
android:parentActivityName="com.example.myapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myapp.MainActivity" />
</activity>
</application>
</manifest>
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/enable_write_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edit_message"
android:layout_centerHorizontal="true"
android:text="@string/Write"
android:onClick="writeToTag"/>
<EditText
android:id="@+id/edit_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:ems="10"
android:hint="" >
<requestFocus />
</EditText>
<Button
android:id="@+id/to_tags"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/enable_write_button"
android:layout_centerHorizontal="true"
android:layout_marginTop="21dp"
android:text="@string/to_tag"
android:onClick="toTag"/>
</RelativeLayout>
activity_tags.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".TagsActivity" >
<Button
android:id="@+id/enable_write_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="81dp"
android:text="@string/TagWriting" />
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/enable_write_button"
android:layout_centerHorizontal="true" />
<EditText
android:id="@+id/edit_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/enable_write_button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="49dp"
android:ems="10"
android:hint="@string/edit_message" >
<requestFocus />
</EditText>
</RelativeLayout>
activity_to_tag.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".ToTagActivity" >
<TextView
android:id="@+id/here"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="80dp"
android:layout_marginTop="51dp"
android:text="@string/Got_Here"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
最后是logcat错误
04-28 21:32:28.240: D/memalloc(20292): /dev/pmem: Mapped buffer base:0x5178b000 size:2641920 offset:2027520 fd:50
04-28 21:32:28.320: D/memalloc(20292): /dev/pmem: Mapped buffer base:0x51dce000 size:3256320 offset:2641920 fd:53
04-28 21:32:28.770: D/memalloc(20292): /dev/pmem: Mapped buffer base:0x522a8000 size:614400 offset:0 fd:56
04-28 21:32:30.760: W/dalvikvm(20292): threadid=1: thread exiting with uncaught exception (group=0x40db71f8)
04-28 21:32:30.780: E/AndroidRuntime(20292): FATAL EXCEPTION: main
04-28 21:32:30.780: E/AndroidRuntime(20292): java.lang.IllegalStateException: Could not execute method of the activity
04-28 21:32:30.780: E/AndroidRuntime(20292): at android.view.View$1.onClick(View.java:3057)
04-28 21:32:30.780: E/AndroidRuntime(20292): at android.view.View.performClick(View.java:3524)
04-28 21:32:30.780: E/AndroidRuntime(20292): at android.view.View$PerformClick.run(View.java:14194)
04-28 21:32:30.780: E/AndroidRuntime(20292): at android.os.Handler.handleCallback(Handler.java:605)
04-28 21:32:30.780: E/AndroidRuntime(20292): at android.os.Handler.dispatchMessage(Handler.java:92)
04-28 21:32:30.780: E/AndroidRuntime(20292): at android.os.Looper.loop(Looper.java:137)
04-28 21:32:30.780: E/AndroidRuntime(20292): at android.app.ActivityThread.main(ActivityThread.java:4476)
04-28 21:32:30.780: E/AndroidRuntime(20292): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 21:32:30.780: E/AndroidRuntime(20292): at java.lang.reflect.Method.invoke(Method.java:511)
04-28 21:32:30.780: E/AndroidRuntime(20292): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:816)
04-28 21:32:30.780: E/AndroidRuntime(20292): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:583)
04-28 21:32:30.780: E/AndroidRuntime(20292): at dalvik.system.NativeStart.main(Native Method)
04-28 21:32:30.780: E/AndroidRuntime(20292): Caused by: java.lang.reflect.InvocationTargetException
04-28 21:32:30.780: E/AndroidRuntime(20292): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 21:32:30.780: E/AndroidRuntime(20292): at java.lang.reflect.Method.invoke(Method.java:511)
04-28 21:32:30.780: E/AndroidRuntime(20292): at android.view.View$1.onClick(View.java:3052)
04-28 21:32:30.780: E/AndroidRuntime(20292): ... 11 more
04-28 21:32:30.780: E/AndroidRuntime(20292): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.myapp/com.example.myapp.ToTag}; have you declared this activity in your AndroidManifest.xml?
04-28 21:32:30.780: E/AndroidRuntime(20292): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1536)
04-28 21:32:30.780: E/AndroidRuntime(20292): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1390)
04-28 21:32:30.780: E/AndroidRuntime(20292): at android.app.Activity.startActivityForResult(Activity.java:3361)
04-28 21:32:30.780: E/AndroidRuntime(20292): at android.app.Activity.startActivity(Activity.java:3468)
04-28 21:32:30.780: E/AndroidRuntime(20292): at com.example.myapp.MainActivity.toTag(MainActivity.java:33)
04-28 21:32:30.780: E/AndroidRuntime(20292): ... 14 more
04-28 21:39:53.060: D/memalloc(20645): /dev/pmem: Mapped buffer base:0x5178b000 size:2641920 offset:2027520 fd:50
04-28 21:39:53.150: D/memalloc(20645): /dev/pmem: Mapped buffer base:0x51b30000 size:3256320 offset:2641920 fd:53
04-28 21:39:53.610: D/memalloc(20645): /dev/pmem: Mapped buffer base:0x5205c000 size:614400 offset:0 fd:56
04-28 21:39:54.170: W/dalvikvm(20645): threadid=1: thread exiting with uncaught exception (group=0x40db71f8)
04-28 21:39:54.180: E/AndroidRuntime(20645): FATAL EXCEPTION: main
04-28 21:39:54.180: E/AndroidRuntime(20645): java.lang.IllegalStateException: Could not execute method of the activity
04-28 21:39:54.180: E/AndroidRuntime(20645): at android.view.View$1.onClick(View.java:3057)
04-28 21:39:54.180: E/AndroidRuntime(20645): at android.view.View.performClick(View.java:3524)
04-28 21:39:54.180: E/AndroidRuntime(20645): at android.view.View$PerformClick.run(View.java:14194)
04-28 21:39:54.180: E/AndroidRuntime(20645): at android.os.Handler.handleCallback(Handler.java:605)
04-28 21:39:54.180: E/AndroidRuntime(20645): at android.os.Handler.dispatchMessage(Handler.java:92)
04-28 21:39:54.180: E/AndroidRuntime(20645): at android.os.Looper.loop(Looper.java:137)
04-28 21:39:54.180: E/AndroidRuntime(20645): at android.app.ActivityThread.main(ActivityThread.java:4476)
04-28 21:39:54.180: E/AndroidRuntime(20645): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 21:39:54.180: E/AndroidRuntime(20645): at java.lang.reflect.Method.invoke(Method.java:511)
04-28 21:39:54.180: E/AndroidRuntime(20645): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:816)
04-28 21:39:54.180: E/AndroidRuntime(20645): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:583)
04-28 21:39:54.180: E/AndroidRuntime(20645): at dalvik.system.NativeStart.main(Native Method)
04-28 21:39:54.180: E/AndroidRuntime(20645): Caused by: java.lang.reflect.InvocationTargetException
04-28 21:39:54.180: E/AndroidRuntime(20645): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 21:39:54.180: E/AndroidRuntime(20645): at java.lang.reflect.Method.invoke(Method.java:511)
04-28 21:39:54.180: E/AndroidRuntime(20645): at android.view.View$1.onClick(View.java:3052)
04-28 21:39:54.180: E/AndroidRuntime(20645): ... 11 more
04-28 21:39:54.180: E/AndroidRuntime(20645): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.myapp/com.example.myapp.ToTag}; have you declared this activity in your AndroidManifest.xml?
04-28 21:39:54.180: E/AndroidRuntime(20645): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1536)
04-28 21:39:54.180: E/AndroidRuntime(20645): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1390)
04-28 21:39:54.180: E/AndroidRuntime(20645): at android.app.Activity.startActivityForResult(Activity.java:3361)
04-28 21:39:54.180: E/AndroidRuntime(20645): at android.app.Activity.startActivity(Activity.java:3468)
04-28 21:39:54.180: E/AndroidRuntime(20645): at com.example.myapp.MainActivity.toTag(MainActivity.java:33)
04-28 21:39:54.180: E/AndroidRuntime(20645): ... 14 more
对于代码墙感到抱歉,但是如果我在早上忘记任何事情,我将无法更新,所以我想要包含所有相关内容。显然这是我在这里发表的第一篇文章,我试图对格式进行研究,但我确定我搞砸了一些事情,所以我提前道歉。
EDIT1:修正了Manifest的“ToTagActivity”而不是“ToTag”。现在我需要找出一些可能类似的过渡到TagsActivity的错误。
EDIT2:修正了我意外尝试将进度条转换为EditText的错误。
EDIT3:明白了!经过一些错误筛选并在网站上搜索后,发现我在清单中忘记了NFC权限!
答案 0 :(得分:2)
您显示注册名为com.example.myapp.ToTagActivity
的活动,但您的类名为com.example.myapp.ToTag
。使用正确的类名更新您的mainifest。
答案 1 :(得分:2)
错误消息
04-28 21:39:54.180: E/AndroidRuntime(20645): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.myapp/com.example.myapp.ToTag}; have you declared this activity in your AndroidManifest.xml?
所以我们检查你Manifest,看起来很好
<activity
android:name="com.example.myapp.ToTagActivity"
但
public class ToTag extends Activity