2013-04-28 90 views
1

我意識到有關於此主題的許多問題,但我已經搜索了有關此問題的每一篇關於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 

對不起,我的代碼牆, b如果直到早上我忘記了任何東西,我將無法更新,所以我想包括所有相關的東西。很明顯,這是我在這裏的第一篇文章,我試圖進行關於格式化的研究,但我確定我搞砸了一些東西,所以我提前道歉。

EDIT1:修正了它具有「ToTagActivity」而非「ToTag」的清單。現在我需要找出一些可能類似的過渡到TagsActivity的錯誤。

編輯2:修正了錯誤,我不小心試圖將進度條投到EditText。

編輯3:明白!經過一些更多的篩選錯誤和搜索周圍的網站後,發現我忘記了我的清單中的NFC許可!

回答

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? 

所以我們檢查你的清單,看起來很好

<activity 
    android:name="com.example.myapp.ToTagActivity" 

public class ToTag extends Activity 
+0

謝謝完美,修復了從MainActivity到ToTag的簡單轉換。所以我知道我至少可以做簡單的轉換工作。現在我必須弄清楚標籤活動的過渡! – bcannariato 2013-04-29 07:59:05

2

您顯然註冊了一個名爲com.example.myapp.ToTagActivity的活動,但您的課程名爲com.example.myapp.ToTag。用正確的類名更新您的mainifest。

+0

好真棒該固定從主到ToTag過渡!謝謝!現在,我必須嘗試篩選錯誤,以找到錯誤的標籤活動過渡 – bcannariato 2013-04-29 07:57:05

相關問題