Android 编辑文本空间的Radiobutton值
嗨,伙计们,我正试图得到它,这样用户就可以选择一个计算单位 我只是单选按钮,我试图选择一个单选按钮,获取存储在那里的字符串的值并显示它 到目前为止,我得到了我的选择,当我要设置的价值,应用程序崩溃 任何想法或帮助都将是伟大的 Java类 Main.xml 在获得更多信息后进行编辑 了解h.setContentViewR.layout.Units和 改变Android 编辑文本空间的Radiobutton值,android,xml,radio-button,Android,Xml,Radio Button,嗨,伙计们,我正试图得到它,这样用户就可以选择一个计算单位 我只是单选按钮,我试图选择一个单选按钮,获取存储在那里的字符串的值并显示它 到目前为止,我得到了我的选择,当我要设置的价值,应用程序崩溃 任何想法或帮助都将是伟大的 Java类 Main.xml 在获得更多信息后进行编辑 了解h.setContentViewR.layout.Units和 改变 findViewById(R.id.radioUnits) 到 说明:radioUnits位于units.xml中,设置为对话框h的布局。 f
findViewById(R.id.radioUnits)
到
说明:radioUnits位于units.xml中,设置为对话框h的布局。
findViewById在活动的布局中查找之前没有任何对象,该布局包含setContentViewR.layout.main,该布局缺少findViewById要查找的视图。如果附加了崩溃日志,则会很有帮助。尝试了此操作,但未成功。xml只是选择单位的布局。u1在主xml中,所有java代码都指向它。我对数字滚轮也有同样的功能,它会很好地进入编辑文本,我不知道为什么radioubtton值不会也打印出来。检查com.example.se414011.biochem1.Sol$8.onClickSol.java:262,它必须有一个空变量,根据您发布的代码,类型必须在units.xml或mQ中,而不是在units.xml中。如果不知道您的活动的onCreate中的布局设置如何,很难帮助您,您的setContentView是什么?@Override public void onCreateBundle savedInstanceState{super.onCreatesavedInstanceState;setContentViewR.layout.main;addListenerOnButton;//addListenerOnButton1;Weight;Req;Calc;但我在拾取单位时将其更改为h.setContentViewR.layout.Units
<EditText
android:id="@+id/u1"
android:background="@android:color/holo_red_dark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/Text1"
android:layout_above="@+id/Text2"
android:layout_toRightOf="@+id/button5"
android:layout_toEndOf="@+id/button5"
android:inputType="textAutoComplete"
/>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<RadioGroup
android:id="@+id/radioUnits"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="match_parent"
android:layout_height="75dp"
android:text="@string/M"
android:id="@+id/M"
android:layout_gravity="center_horizontal"
android:checked="true" />
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/mM"
android:inputType="text"
android:id="@+id/mM"
android:layout_gravity="center_horizontal"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/uM"
android:id="@+id/uM"
android:layout_gravity="center_horizontal"
android:layout_weight="0.09"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/pM"
android:id="@+id/pM"
android:layout_gravity="center_horizontal"
android:layout_weight="0.09"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/cM"
android:id="@+id/cM"
android:layout_gravity="center_horizontal"
android:layout_weight="0.09"/>
</RadioGroup>
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set"
android:layout_weight="0.15"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="68dp"
android:layout_marginBottom="133dp" />
<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_gravity="right"
android:layout_alignTop="@+id/b1"
android:layout_toRightOf="@+id/b1"
android:layout_toEndOf="@+id/b1"
android:layout_marginLeft="77dp" />
</RelativeLayout>
12-05 16:38:55.406 743-743/com.example.se414011.biochem1 E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at com.example.se414011.biochem1.Sol$8.onClick(Sol.java:262)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnButton();
...
findViewById(R.id.radioUnits)
h.findViewById(R.id.radioUnits)