我在android中有问题。在我的程序中,有一个活动在viewpager中包含4个片段。从其中一个片段,我想调用一个对话活动,并发送一个变量。这是我的代码:
Intent popup = new Intent(getActivity().getApplicationContext(),
PopUpWifi.class); popup.putExtra("WiFiID", String.valueOf(name));
startActivity(popup);
以下是弹出活动的代码:
public class PopUpWifi extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popupwifi);
TextView TVWifi = (TextView) findViewById(R.id.TVWifi);
EditText ETJelszo = (EditText) findViewById(R.id.ETJelszo);
String value = getIntent().getStringExtra("WiFiID");
TVWifi.setText(value);
} }
这是pupupwifi.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Wi-fi hálózat neve"
android:textSize="@dimen/NewSize" />
<TextView
android:name="@+id/TVWifi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Wi-fi"
android:textSize="@dimen/NewSize" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Kérem adja meg a jelszót:"
android:textSize="@dimen/NewSize" />
<EditText
android:id="@+id/ETJelszo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/NewSize" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Bevitel"
android:textSize="@dimen/NewSize" />
</LinearLayout>
但是我可以尝试任何东西,它会抛出一个nullpointer异常:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sss.home/com.sss.home.PopUpWifi}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2372)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
at android.app.ActivityThread.access$600(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5400)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:837)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.sss.home.PopUpWifi.onCreate(PopUpWifi.java:20)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1084)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2336)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
at android.app.ActivityThread.access$600(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5400)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:837)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
at dalvik.system.NativeStart.main(Native Method)
感谢您的帮助。
答案 0 :(得分:0)
尝试使用android:id="@+id/TVWifi"
而不是android:name="@+id/TVWifi"