Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I set intent data to current activity editText?
    primarykey
    data
    text
    <p>I'm trying to transfer two numerical inputs from one activity to another's UI but when I click the button to change intent it crashes.</p> <p>I get the following in logcat: <a href="http://pastebin.com/zkWPcSNZ" rel="nofollow">http://pastebin.com/zkWPcSNZ</a> , which suggests a problem with the way I parsed the data to the editTexts in CalcResult.</p> <p>My question is what is wrong with the way I'm trying to pass the data to the CalcResult editText.Is there an alternative method of acheiving this?</p> <p>My two classes look like this for reference:</p> <pre><code>public class MainActivity extends Activity implements OnClickListener { //variables for xml objects EditText offsetLength,offsetDepth,ductDepth; Button calculate; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //setting the variables to the xml id's and setting the click listener on the calc button offsetLength = (EditText)findViewById(R.id.offLength); offsetDepth = (EditText)findViewById(R.id.offDepth); ductDepth = (EditText)findViewById(R.id.ductDepth); calculate = (Button)findViewById(R.id.calc); calculate.setOnClickListener(this);//don't cast the listener to OnClickListener } @Override public void onClick(View v) { // TODO Auto-generated method stub try { String getoffsetlength = offsetLength.getText().toString(); String getoffsetdepth = offsetDepth.getText().toString(); String getductdepth = ductDepth.getText().toString(); double tri1,tri2; double marking1,marking2; double off1 = Double.parseDouble(getoffsetlength); double off2 = Double.parseDouble(getoffsetdepth); double off3 = Double.parseDouble(getductdepth) ; marking1 = Math.pow(off1,2) + Math.pow(off2,2); tri1 = (float)off2/(float)off1; tri2 = (float)off3/Math.atan((float)tri1); marking2 = (float)off3/Math.atan(tri2); Intent myIntent = new Intent(MainActivity.this, CalcResult.class); myIntent.putExtra("numbers", marking1); myIntent.putExtra("numbers", marking2); startActivity(myIntent); } catch (NumberFormatException e) { // TODO: handle exception System.out.println("Must enter a numeric value!"); } } } </code></pre> <p>This is the activity that I'm passing the data to:</p> <pre><code>public class CalcResult extends MainActivity { EditText result1,result2; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.result); result1 = (EditText)findViewById(R.id.mark1); result2 = (EditText)findViewById(R.id.mark2); Intent intent = getIntent(); Bundle bundle = intent.getExtras(); double mark1 = bundle.getDouble("number1"); double mark2 = bundle.getDouble("number2"); int a = Integer.valueOf(result1.getText().toString()); int b = Integer.valueOf(result2.getText().toString()); result1.setText(a + " "); result2.setText(b + " "); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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