AsyncTask

@Override protected void onPostExecute(String result) { super.onPostExecute(result); if (chararray != null) while (i < chararray.length ) try { {charS = Character.toString(chararray[i]); TimeUnit.MILLISECONDS.sleep(50); Intent broadcastIntent = new Intent(); broadcastIntent.setAction("PROCESS_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("text1", charS); context.sendBroadcast(broadcastIntent); i++;} 

Receiver

 class RequestReceiver extends BroadcastReceiver { public static final String PROCESS_RESPONSE = "PROCESS_RESPONSE"; @Override public void onReceive(Context context, Intent intent) { String text1 = intent.getStringExtra("text1"); TextView tv3 = (TextView) ((body)context).tv3; updateUI(text1, tv3); } private void updateUI(String text1, TextView tv3) { tv3.setText(tv3.getText() + text1); } } 

Watched the process in the debugger. The array and string are fine, but further on, from somewhere, Null is taken.

  • The crystal ball broke. Where exactly is null? - GreyGoblin
  • Where does he even come from? Better yet, attach the stektrays. - temq
  • Hike, the problem in this line is context.sendBroadcast (broadcastIntent); . Honestly, I don’t know what should be instead of "context" - FullyRetarded
  • "context." remove - iFr0z

1 answer 1

Instead

 tv3.setText(tv3.getText() + text1); 

It must be something like:

 CharSequence oldText = tv3.getText(); if (TextUtils.isEmpty(oldText)) { tv3.setText(text1); } else { tv3.setText(oldText.toString() + text1); } 

Those. The problem is that initially the text in your tv3 is not set, and you are trying to glue a null with another text.

  • Maybe try tv3.setText(""+tv3.getText() + text1); - Saidolim
  • @Saidolim Your option will not fix the problem. At the first call it will look like tv3.setText("" + null + text1); - lllyct