2013-09-22 116 views
0

我有兩個活動顯示和查看。我宣佈觀活動在manifest.xml但後來也是其投擲的錯誤,並得到上單擊任何按鈕,我傳遞的配置文件名稱爲意外而不是在拋出清單錯誤時聲明活動

的manifest.xml

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme"> 
    <activity 
     android:name="com.abhishekp.passmanage.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.abhishekp.passmanage.Create" > </activity> 
    <activity android:name="com.abhishekp.passmanage.Details" > </activity> 
    <activity android:name="com.abhishekp.passmanage.Setting" > </activity> 
    <activity android:name="com.abhishekp.passmanage.Show" > </activity> 
    <activity android:name="com.abhishekp.passmanage.View"> </activity> 


    </application> 

</manifest> 

show.xml

關閉

public class Show extends Activity { 

Button showhome,atm,bank,mail,mobile,other,personal,social; 
String profile; 



@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.show); 

//buttons id declarations 

    showhome.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View view) { 
      Intent main = new Intent(getApplicationContext(), MainActivity.class); 
      profile = "SHOW"; 
      main.putExtra("key", profile); 
      startActivityForResult(main, 0); 
     } 

    }); 

    atm.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View view) { 

      Intent d1 = new Intent(getApplicationContext(), View.class); 
      profile = "ATM"; 
      d1.putExtra("key", profile); 
      startActivityForResult(d1, 0); 
     } 
    }); 

    bank.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View view) { 
      profile="BANK"; 
      Intent d2 = new Intent(getApplicationContext(), View.class); 
      d2.putExtra("key", profile); 
      startActivityForResult(d2, 0); 
     } 
    }); 

    mail.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View view) { 
      profile="MAIL"; 
      Intent d3 = new Intent(getApplicationContext(), View.class); 
      d3.putExtra("key", profile); 
      startActivityForResult(d3, 0); 
     } 
    }); 

鑑於活動我只有1個TextView的 從活性我試圖讓值

package com.abhishekp.passmanage; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 

public class View extends Activity { 

TextView profilename; 
String profile; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.view); 


    profilename = (TextView)findViewById(R.id.profilename); 


    Bundle extras = getIntent().getExtras(); 
    if (extras != null) 
    { 
     profile = extras.getString("key"); 
     profilename.setText("Profile : " +profile); 
    } 

} 

} 

但它扔在日誌貓一個錯誤

LOGCAT 

09-22 16:18:27.267: E/AndroidRuntime(558): FATAL EXCEPTION: main 
09-22 16:18:27.267: E/AndroidRuntime(558): android.content.ActivityNotFoundException:  Unable to find explicit activity class {com.abhishekp.passmanage/android.view.View}; have you declared this activity in your AndroidManifest.xml? 
09-22 16:18:27.267: E/AndroidRuntime(558): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404) 
09-22 16:18:27.267: E/AndroidRuntime(558): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378) 
09-22 16:18:27.267: E/AndroidRuntime(558): at android.app.Activity.startActivityForResult(Activity.java:2817) 
09-22 16:18:27.267: E/AndroidRuntime(558): at com.abhishekp.passmanage.Show$2.onClick(Show.java:50) 
09-22 16:18:27.267: E/AndroidRuntime(558): at android.view.View.performClick(View.java:2408) 
09-22 16:18:27.267: E/AndroidRuntime(558): at android.view.View$PerformClick.run(View.java:8816) 
09-22 16:18:27.267: E/AndroidRuntime(558): at android.os.Handler.handleCallback(Handler.java:587) 
09-22 16:18:27.267: E/AndroidRuntime(558): at android.os.Handler.dispatchMessage(Handler.java:92) 
09-22 16:18:27.267: E/AndroidRuntime(558): at android.os.Looper.loop(Looper.java:123) 
09-22 16:18:27.267: E/AndroidRuntime(558): at android.app.ActivityThread.main(ActivityThread.java:4627) 
09-22 16:18:27.267: E/AndroidRuntime(558): at java.lang.reflect.Method.invokeNative(Native Method) 
09-22 16:18:27.267: E/AndroidRuntime(558): at java.lang.reflect.Method.invoke(Method.java:521) 
09-22 16:18:27.267: E/AndroidRuntime(558): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
09-22 16:18:27.267: E/AndroidRuntime(558): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
09-22 16:18:27.267: E/AndroidRuntime(558): at dalvik.system.NativeStart.main(Native Method) 
09-22 16:18:33.766: I/Process(558): Sending signal. PID: 558 SIG: 9 
+1

重命名您的視圖活動類,並儘量避免混淆 – Raghunandan

+0

您是否有正確的View類導入?可能你已經導入了android視圖。 – Bracadabra

回答

1

因爲View類已經在Android中可用,以便更改類名或使用setClasssetComponent開始活動爲:

Intent intent = new Intent(); 
intent.setClassName("com.abhishekp.passmanage", 
              "com.abhishekp.passmanage.View"); 
intent.setComponent(new ComponentName("com.abhishekp.passmanage", 
              "com.abhishekp.passmanage.View")); 
startActivity(intent); 
+0

你是對的我改變了類的名稱,並在清單中改變它的工作.. – Abb

+1

@Abhishek:你也可以通過使用setClassName和setComponent向系統提供大量信息而無需更改顯式文件中的名稱來啓動活動活動。 –

+0

好的..我以第一種方式嘗試 – Abb

相關問題