我有两个活动展示和查看。我已经在 manifest.xml 中声明了视图活动,但也声明了它的抛出错误并意外关闭
清单.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>
单击任何按钮时,我将配置文件名称传递为
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 个文本视图,在视图活动中,我试图将值设为
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);
}
}
}
但它在 log cat 中引发错误
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