Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try this.</p> <p>You must call <code>findViewById</code> once after called the <code>setContentView</code> method.</p> <pre><code>private RadioButton RD1 private RadioButton RD2 private EditText input; private EditText output; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); RD1 = (RadioButton) findViewById(R.id.ctof); RD2 = (RadioButton) findViewById(R.id.ftoc); input = (EditText) findViewById(R.id.ipdata); output = (EditText) findViewById(R.id.opdata); } </code></pre> <p>Edit this line in doconvert method.</p> <pre><code>float data = Float.parseFloat(input.getText().toString()); </code></pre> <p>Edit in your layout.</p> <pre><code>&lt;EditText android:id="@+id/ipdata" android:hint="Enter temperature" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="22dp" android:ems="10" android:inputType="number"/&gt; &lt;&lt;&lt;Add this line to force user to enter the numeric value. </code></pre> <p>Set this input type to number because user can enter anything in <code>edittext</code> like text also then <code>NumberFormatException</code> will throw on this line.</p> <pre><code>float data = Float.parseFloat(input.getText().toString()); </code></pre> <p>So you also want user should enter numeric then set the <code>android:inputType="number"</code> and last set the <code>android:onClick="doconvert"</code> in <code>button</code> in layout as @user113215 edited answer.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload