Note that there are some explanatory texts on larger screens.

plurals
  1. POthreads in android no output
    text
    copied!<p>I've created an android app where the user inputs a string and a number, where the number will be calculated to its factorial. Everything's working fine but when i enclose my code inside the thread there's no output.</p> <p>here's my source code:</p> <pre><code>package com.inputandfactorial; import android.app.Activity; import android.os.Bundle; import android.text.Editable; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends Activity { Button chkCmd; EditText input1, input2; TextView display1, display2; int res = 1,factint; String fact; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); chkCmd = (Button) findViewById(R.id.bProcess); input1 = (EditText) findViewById(R.id.etString); input2 = (EditText) findViewById(R.id.etFactorial); display1 = (TextView) findViewById(R.id.tvString); display2 = (TextView) findViewById(R.id.tvFactorial); chkCmd.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Thread t1 = new Thread(){ public void run(){ String change = input1.getText().toString(); fact = input2.getText().toString(); factint = Integer.parseInt(fact); for (int i = 1; i &lt;= factint; i++) { res = res * i; } try { display2.setText("The factorial of " + fact + " is " + res); display1.setText("The string value is " + change); } catch (Exception e) { } } }; t1.start(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } } </code></pre> <p>I know i don't need to put it in a thread, i just was just experiment to see if this will work and it didn't.</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