我的 JAVA 课程:
package com.example.myprojectname;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Data extends Activity implements OnClickListener{
Button start, startFor;
EditText sendET;
TextView gotAnswer;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.get);
initialize();
}
private void initialize() {
start = (Button) findViewById(R.id.bSA);
startFor = (Button) findViewById(R.id.bSAFR);
sendET = (EditText) findViewById(R.id.etSend);
gotAnswer = (TextView) findViewById(R.id.tvGot);
start.setOnClickListener(this);
startFor.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch (arg0.getId()){
case R.id.bSA:
String bread = sendET.getText().toString();
Bundle basket = new Bundle();
basket.putString("key", bread);
Intent a = new Intent (Data.this, OpenedClass.class);
a.putExtras(basket);
startActivity(a);
break;
case R.id.bSAFR:
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK){
Bundle basket = data.getExtras();
String s = basket.getString("answer");
gotAnswer.setText(s);
}
}
}
我的xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<EditText
android:id="@+id/etSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</EditText>
<Button
android:layout_below="@id/etSend"
android:layout_alignParentRight="true"
android:id="@+id/bSA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="StartActivity" />
<Button
android:layout_toLeftOf="@id/bSA"
android:layout_alignTop="@+id/bSA"
android:id="@+id/bSAFR"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="StartActivityResult" />
<TextView
android:layout_below="@id/bSAFR"
android:id="@+id/tvGot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</RelativeLayout>``
和我的问题LOGCAT:
11-14 15:58:46.177: D/AndroidRuntime(277): Shutting down VM
11-14 15:58:46.177: W/dalvikvm(277): threadid=1: thread exiting with (group=0x4001d800)
11-14 15:58:46.197: E/AndroidRuntime(277): FATAL EXCEPTION: main
11-14 15:58:46.197: E/AndroidRuntime(277): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.myprojectname/com.example.myprojectname.Data}; have you declared this activity in your AndroidManifest.xml?
11-14 15:58:46.197: E/AndroidRuntime(277): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
11-14 15:58:46.197: E/AndroidRuntime(277): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
11-14 15:58:46.197: E/AndroidRuntime(277): at android.app.Activity.startActivityForResult(Activity.java:2817)
11-14 15:58:46.197: E/AndroidRuntime(277): at android.app.Activity.startActivity(Activity.java:2923)
11-14 15:58:46.197: E/AndroidRuntime(277): at com.example.myprojectname.Menu.onListItemClick(Menu.java:35)
11-14 15:58:46.197: E/AndroidRuntime(277): at android.app.ListActivity$2.onItemClick(ListActivity.java:321)
11-14 15:58:46.197: E/AndroidRuntime(277): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
11-14 15:58:46.197: E/AndroidRuntime(277): at android.widget.ListView.performItemClick(ListView.java:3382)
11-14 15:58:46.197: E/AndroidRuntime(277): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
11-14 15:58:46.197: E/AndroidRuntime(277): at android.os.Handler.handleCallback(Handler.java:587)
11-14 15:58:46.197: E/AndroidRuntime(277): at android.os.Handler.dispatchMessage(Handler.java:92)
11-14 15:58:46.197: E/AndroidRuntime(277): at android.os.Looper.loop(Looper.java:123)
11-14 15:58:46.197: E/AndroidRuntime(277): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-14 15:58:46.197: E/AndroidRuntime(277): at java.lang.reflect.Method.invokeNative(Native Method)
11-14 15:58:46.197: E/AndroidRuntime(277): at java.lang.reflect.Method.invoke(Method.java:521)
11-14 15:58:46.197: E/AndroidRuntime(277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-14 15:58:46.197: E/AndroidRuntime(277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-14 15:58:46.197: E/AndroidRuntime(277): at dalvik.system.NativeStart.main(Native Method)