Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.lang.NullPointerException in textview inside asyncTask
    primarykey
    data
    text
    <p>If i use the following code, i will have no error, but there will be a freeze time.</p> <blockquote> <p>`@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); setContentView(R.layout.profilepic);</p> </blockquote> <pre><code> initialize(); Bundle bundle = getIntent().getExtras(); email = bundle.getString("Email"); ArrayList&lt;NameValuePair&gt; postParameters; String response = null; postParameters = new ArrayList&lt;NameValuePair&gt;(); postParameters.add(new BasicNameValuePair("emaillog", email)); try { response = CustomHttpClient.executeHttpPost("http://whatstherex.info/checkU.php", postParameters); res = response.toString(); res = res.replaceAll("null", ""); username = res.toString(); tvProfilePic.setText("Hi " + username + ", you are encourage to add a profile picture."); }catch(Exception e){ res = e.toString(); tvProfilePic.setText(res); } }` </code></pre> <p>But if i use this code with asynctask and progressDialog like this:</p> <blockquote> <p>`@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); setContentView(R.layout.profilepic);</p> </blockquote> <pre><code> initialize(); getUsername(); } </code></pre> <p>private AsyncTask task;</p> <pre><code>public void getUsername(){ Bundle bundle = getIntent().getExtras(); email = bundle.getString("Email"); task = new AsyncTask&lt;String, Void, String&gt;() { ProgressDialog dialog; ArrayList&lt;NameValuePair&gt; postParameters; String response = null; @Override protected void onPreExecute() { // ArrayList&lt;NameValuePair&gt; postParameters = new ArrayList&lt;NameValuePair&gt;(); postParameters.add(new BasicNameValuePair("emaillog", email)); dialog = new ProgressDialog(Profilepic.this, ProgressDialog.STYLE_SPINNER); dialog.setMessage("Loading Data..."); dialog.show(); } @Override protected String doInBackground(String... params) { // try { response = CustomHttpClient.executeHttpPost("http://whatstherex.info/checkU.php", postParameters); res = response.toString(); res = res.replaceAll("null", ""); username = res.toString(); return username; }catch(Exception e){ res = e.toString(); return res; } } @Override protected void onPostExecute(String result) { if(result.length()&lt; 25){ username = result; tvProfilePic.setText("Hi " + result + ", you are encourage to add a profile picture."); dialog.dismiss(); }else{ tvProfilePic.setText(result); dialog.dismiss(); } } }; task.execute(); }` </code></pre> <p>i'll then get java.lang.NullPointerException in the textview.</p> <p>Whats the problem can anyone guide me? thank you</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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