2012-06-04 71 views
4
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.suven.Create_memo } 

我只想從一個活動去另一個活動,但它給了我這個錯誤。如何解決「找不到處理意圖的活動」錯誤

我的主要活動代碼是folllow

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    btn1 = (Button)findViewById(R.id.button1); 
    btn1.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) 
     { 
      try 
      { 
       Intent i=new Intent("com.android.suven.Create_memo"); 
      startActivity(i); 
      } 
      catch (ActivityNotFoundException e) { 
       e.printStackTrace(); 
      } 

     } 

    }); 
    btn2 = (Button)findViewById(R.id.button2); 
    btn2.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) 
     { 
      try 
      { 
       Intent i=new Intent("com.android.suven.Create_memo"); 
      startActivity(i); 
      } 
      catch (ActivityNotFoundException e) { 
       e.printStackTrace(); 
      } 

    });   
    } 
} 

我logcat的是這樣的:

06-05 13:43:35.959: E/AndroidRuntime(275): FATAL EXCEPTION: main 
06-05 13:43:35.959: E/AndroidRuntime(275): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.suven/com.android.suven.Create_memo}: java.lang.NullPointerException 
06-05 13:43:35.959: E/AndroidRuntime(275): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 
06-05 13:43:35.959: E/AndroidRuntime(275): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
06-05 13:43:35.959: E/AndroidRuntime(275): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
06-05 13:43:35.959: E/AndroidRuntime(275): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
06-05 13:43:35.959: E/AndroidRuntime(275): at android.os.Handler.dispatchMessage(Handler.java:99) 
06-05 13:43:35.959: E/AndroidRuntime(275): at android.os.Looper.loop(Looper.java:123) 
06-05 13:43:35.959: E/AndroidRuntime(275): at android.app.ActivityThread.main(ActivityThread.java:4627) 
06-05 13:43:35.959: E/AndroidRuntime(275): at java.lang.reflect.Method.invokeNative(Native Method) 
06-05 13:43:35.959: E/AndroidRuntime(275): at java.lang.reflect.Method.invoke(Method.java:521) 
06-05 13:43:35.959: E/AndroidRuntime(275): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
06-05 13:43:35.959: E/AndroidRuntime(275): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
06-05 13:43:35.959: E/AndroidRuntime(275): at dalvik.system.NativeStart.main(Native Method) 
06-05 13:43:35.959: E/AndroidRuntime(275): Caused by: java.lang.NullPointerException 
06-05 13:43:35.959: E/AndroidRuntime(275): at com.android.suven.Create_memo.onCreate(Create_memo.java:56) 
06-05 13:43:35.959: E/AndroidRuntime(275): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
06-05 13:43:35.959: E/AndroidRuntime(275): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 
06-05 13:43:35.959: E/AndroidRuntime(275): ... 11 more 
06-05 13:43:39.199: I/Process(275): Sending signal. PID: 275 SIG: 9 
+0

條目你加你的活動在'AndroidManifest.xml'? – Shaiful

+0

Hi @shubh您應該使用packagedecleration或不使用decleration將您的活動名稱添加到AdroidManifest.xml文件中。 – itsrajesh4uguys

+0

雅我在menifest bt中添加了我的活動,但它仍然給出了一個錯誤..我試過所有的意圖bt不工作的語法n每次都得到相同的錯誤。 – shubh

回答

0

你有沒有在您的清單文件中聲明Create_memo活動?這樣的:在你的代碼行

Intent i=new Intent("com.android.suven.Create_memo"); 

「com.android.suven.Create_memo」

<activity 
      android:name="com.android.suven.Create_memo" /> 
3

被視爲行動。

相反,你必須把

Intent i=new Intent(YourCurrentAivityName.this, Create_memo.class); 

也把

<activity 
      android:name=".Create_memo" > 
     </activity> 

在AndroidManifest.xml文件。

0

這是NextActivity.java

public class NextActivity extends Activity { 

//Your member variable declaration here 

// Called when the activity is first created. 
@Override 
public void onCreate(Bundle savedInstanceState) { 
//Your code here 
} 
} 

創建一個新的活動之後,我們在文件「AndroidManifest.xml中」進行註冊。 爲了記錄我們必須創造「的AndroidManifest.xml」作爲

**<activity android:name=".NextActivity" android:label="@string/app_name"/>** 
相關問題