目的是从编辑视图中获取文本,并在单击按钮时在另一个活动中的TextView
中显示该文本。我的问题:只要我点击按钮,应用就会停止。
Main.java:
package com.satish.explicitintents;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText et = (EditText) findViewById(R.id.editText1);
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent =new Intent(Main.this, Second.class);
intent.putExtra("thetext", et.getText().toString());
startActivity(intent);
}
});
}
}
Second.java:
package com.satish.explicitintents;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Second extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(getIntent().getExtras().getString("thetext"));
}
}
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.satish.explicitintents"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.satish.explicitintents.Main"
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.satish.explicitintent.Second"
android:label="@string/app_name"/>
</application>
</manifest>
堆栈跟踪:
02-23 17:42:03.124: D/AndroidRuntime(4445): Shutting down VM
02-23 17:42:03.124: W/dalvikvm(4445): threadid=1: thread exiting with uncaught exception (group=0x40015560)
02-23 17:42:03.144: E/AndroidRuntime(4445): FATAL EXCEPTION: main
02-23 17:42:03.144: E/AndroidRuntime(4445): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.satish.explicitintents/com.satish.explicitintents.Second}; have you declared this activity in your AndroidManifest.xml?
02-23 17:42:03.144: E/AndroidRuntime(4445): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
02-23 17:42:03.144: E/AndroidRuntime(4445): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
02-23 17:42:03.144: E/AndroidRuntime(4445): at android.app.Activity.startActivityForResult(Activity.java:2827)
02-23 17:42:03.144: E/AndroidRuntime(4445): at android.app.Activity.startActivity(Activity.java:2933)
02-23 17:42:03.144: E/AndroidRuntime(4445): at com.satish.explicitintents.Main$1.onClick(Main.java:28)
02-23 17:42:03.144: E/AndroidRuntime(4445): at android.view.View.performClick(View.java:2485)
02-23 17:42:03.144: E/AndroidRuntime(4445): at android.view.View$PerformClick.run(View.java:9080)
02-23 17:42:03.144: E/AndroidRuntime(4445): at android.os.Handler.handleCallback(Handler.java:587)
02-23 17:42:03.144: E/AndroidRuntime(4445): at android.os.Handler.dispatchMessage(Handler.java:92)
02-23 17:42:03.144: E/AndroidRuntime(4445): at android.os.Looper.loop(Looper.java:123)
02-23 17:42:03.144: E/AndroidRuntime(4445): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-23 17:42:03.144: E/AndroidRuntime(4445): at java.lang.reflect.Method.invokeNative(Native Method)
02-23 17:42:03.144: E/AndroidRuntime(4445): at java.lang.reflect.Method.invoke(Method.java:507)
02-23 17:42:03.144: E/AndroidRuntime(4445): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-23 17:42:03.144: E/AndroidRuntime(4445): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-23 17:42:03.144: E/AndroidRuntime(4445): at dalvik.system.NativeStart.main(Native Method)
02-23 17:42:24.654: W/KeyCharacterMap(4455): No keyboard for id 0
02-23 17:42:24.654: W/KeyCharacterMap(4455): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
02-23 17:42:25.904: D/AndroidRuntime(4455): Shutting down VM
02-23 17:42:25.904: W/dalvikvm(4455): threadid=1: thread exiting with uncaught exception (group=0x40015560)
02-23 17:42:25.924: E/AndroidRuntime(4455): FATAL EXCEPTION: main
02-23 17:42:25.924: E/AndroidRuntime(4455): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.satish.explicitintents/com.satish.explicitintents.Second}; have you declared this activity in your AndroidManifest.xml?
02-23 17:42:25.924: E/AndroidRuntime(4455): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
02-23 17:42:25.924: E/AndroidRuntime(4455): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
02-23 17:42:25.924: E/AndroidRuntime(4455): at android.app.Activity.startActivityForResult(Activity.java:2827)
02-23 17:42:25.924: E/AndroidRuntime(4455): at android.app.Activity.startActivity(Activity.java:2933)
02-23 17:42:25.924: E/AndroidRuntime(4455): at com.satish.explicitintents.Main$1.onClick(Main.java:28)
02-23 17:42:25.924: E/AndroidRuntime(4455): at android.view.View.performClick(View.java:2485)
02-23 17:42:25.924: E/AndroidRuntime(4455): at android.view.View$PerformClick.run(View.java:9080)
02-23 17:42:25.924: E/AndroidRuntime(4455): at android.os.Handler.handleCallback(Handler.java:587)
02-23 17:42:25.924: E/AndroidRuntime(4455): at android.os.Handler.dispatchMessage(Handler.java:92)
02-23 17:42:25.924: E/AndroidRuntime(4455): at android.os.Looper.loop(Looper.java:123)
02-23 17:42:25.924: E/AndroidRuntime(4455): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-23 17:42:25.924: E/AndroidRuntime(4455): at java.lang.reflect.Method.invokeNative(Native Method)
02-23 17:42:25.924: E/AndroidRuntime(4455): at java.lang.reflect.Method.invoke(Method.java:507)
02-23 17:42:25.924: E/AndroidRuntime(4455): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-23 17:42:25.924: E/AndroidRuntime(4455): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-23 17:42:25.924: E/AndroidRuntime(4455): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
android.content.ActivityNotFoundException:无法找到显式 活动课 {com.satish.explicitintents / com.satish.explicitintents.Second};有 你在AndroidManifest.xml中声明了这个活动吗?
堆栈跟踪表明您尚未在清单中声明活动。
您的包名错误
更改为
<activity android:name="com.satish.explicitintents.Second"
//explicitintents not explicitintent
检查
package="com.satish.explicitintents"
或者只是
<activity android:name=".Second"
答案 1 :(得分:0)
问题出在您的清单文件中。替换以下行 -
<activity android:name="com.satish.explicitintent.Second"
android:label="@string/app_name"/>
与 -
<activity android:name="com.satish.explicitintents.Second"
android:label="@string/app_name"/>
您的包裹名称错误。
答案 2 :(得分:0)
在指定第二个活动的路径时,清单文件中有错误。你需要使用:
<activity android:name="com.satish.explicitintents.Second"
android:label="@string/app_name"/>