80,471
社区成员




package com.Adr.work3;
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;
public class Adr3Activity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.OK);
button.setOnClickListener(myname);
}
private OnClickListener myname = new OnClickListener() {
@Override
public void onClick(View v) {
EditText inname = (EditText) findViewById(R.id.name);
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("NAME", inname.getText().toString());
intent.putExtras(bundle);
intent.setClass(Adr3Activity.this, Welcome.class);
startActivity(intent);
}
};
}
package com.Adr.work3;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Welcome extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
TextView receivename=(TextView) findViewById(R.id.welcome_name);
Bundle bundle=this.getIntent().getExtras();
String name=bundle.getString("NAME");
receivename.setText(name);
}
}
package com.Adr.work3;
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;
public class Adr3Activity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.OK);
button.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
EditText inname = (EditText) findViewById(R.id.name);
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("NAME", inname.getText().toString());
intent.putExtras(bundle);
intent.setClass(Adr3Activity.this, Welcome.class);
startActivity(intent);
}
});
}
}
receivename.setText(name);
这句空指针。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="请输入内容"
/>
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<Button
android:id="@+id/OK"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="OK"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:name="@+id/welcome_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
</LinearLayout>