Samsung G5 nullpointerexception by accessibility

Android application code works successfully on a variety of devices including API 14 and up to API 19 (target). However Samsung G5 v4.4.4 throws NPE when trying to set Visibilty (true) for activity. This error can only start after a recent G5 OS update via download from Sprint. We've covered many varieties of NPE issues and Samsung specific questions, but none of them apply.

Magazine:

01-08 20: 58: 40.122: W / dalvikvm (7972): threadid = 1: thread exiting with uncaught exception (group = 0x41963da0)

01-08 20: 58: 40.132: W / System.err (7972): java.lang.NullPointerException

01-08 20: 58: 40.132: W / System.err (7972): at android.app.Activity.makeVisible (Activity.java:4355)

01-08 20: 58: 40.142: W / System.err (7972): at android.app.Activity.setVisible (Activity.java:4336)

01-08 20: 58: 40.142: W / System.err (7972): at com.taskassure.app.StartTaskActivity.setActivityVisible (StartTaskActivity.java:531)

01-08 20: 58: 40.142: W / System.err (7972): at com.taskassure.app.StartTaskActivity.access $ 1 (StartTaskActivity.java:529)

01-08 20: 58: 40.142: W / System.err (7972): at com.taskassure.app.StartTaskActivity $ 4.run (StartTaskActivity.java:298)

01-08 20: 58: 40.142: W / System.err (7972): at android.os.Handler.handleCallback (Handler.java:733)

01-08 20: 58: 40.142: W / System.err (7972): at android.os.Handler.dispatchMessage (Handler.java:95)

01-08 20: 58: 40.142: W / System.err (7972): at android.os.Looper.loop (Looper.java:146)

01-08 20: 58: 40.142: W / System.err (7972): at android.app.ActivityThread.main (ActivityThread.java:5678)

01-08 20: 58: 40.142: W / System.err (7972): on java.lang.reflect.Method.invokeNative (native method)

01-08 20: 58: 40.152: W / System.err (7972): in java.lang.reflect.Method.invoke (Method.java:515)

01-08 20: 58: 40.152: W / System.err (7972): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1291)

01-08 20: 58: 40.152: W / System.err (7972): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1107)

01-08 20: 58: 40.152: W / System.err (7972): at dalvik.system.NativeStart.main (native method)

An overview of StartTaskActivity confirms that we are trying to set visibility to true when throwing an exception. Related code segments include:

Actions that will start the failed activity (StartTaskActivity):

/**
* The intent to open the task start confirm dialog. Put in globalspace so
* that data can be added to it from anywhere in this class.
*/
public intent      confirmActivity  = null;

/**
* Sets up the tab view showing the task details and checkpoints, as well as
* setting up the location client to get the most recent location.
*/

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.view_task_activity);
// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

...

// initialize confirmActivity so we can add the necessary
// information from our fragments
confirmActivity = new Intent(getApplicationContext(),
    StartTaskActivity.class);
}

      

Associated methods in the class that will launch StartTaskActivity

/ ** * Sends a request to start a task to the server, returns a checkpoint * of warnings that need to be overridden before we can start the task. by * overriding any warnings (if any), StartTaskActivity starts. * /

private void requestTaskStart()
{

...
          try
          {
            JSONObject JsonResponse = new JSONObject(responseBody);
            JSONArray checkpoints = (JSONArray) JsonResponse
                .get("chekpoint_status");

            JSONObject userData = new JSONObject(getIntent().getExtras()
                .getString("user"));
            userData = userData.getJSONObject("user");
            confirmActivity.putExtra("training_set_size", new JSONObject(
                getIntent().getExtras().getString("user"))
                .getInt("training_set_size"));
            confirmActivity.putExtra("requestStartInfo",
                responseBody);
            confirmActivity.putExtra("user_id",
                Integer.parseInt(userData.getString("id")));
            confirmActivity.putExtra("taskId", task.getInt("id"));

            mDialog.dismiss();

            // show checkpoint override if there are any
            if ( checkpoints.length() != 0 )
            {
              // show first checkpoint dialog
              showCheckpointDialog(checkpoints, 0);
            }
            else
            {
              startActivityForResult(confirmActivity,
                  CONFIRM_TASK_START);
            }

      

StartTaskActivity - Activity class that throws NPE on Samsung G5

/**
* Activity that is shown after choosing to start a task. Shows the confirmation
* window before a task is started. This activity also handles starting face
* verification if necessary.
*/

public class StartTaskActivity extends Activity
{
    ...
/**
* Creates the task confirm screen, downloads the users photo from the server.
* Checks the task checkpoints to see if face verification needs to be done
* before starting the task. Keeps the activity invisible until all
* checkpoints are properly met.
*/
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.start_task_confirm_layout);

    Intent launchIntent = getIntent();
    Bundle args = launchIntent.getExtras();

    try
    {
      requestTaskStartData = new JSONObject(args.getString("requestStartInfo"));
      taskCheckpoints = new JSONArray(args.getString("checkpoints"));
      taskId = args.getInt("taskId");

      ((TextView) findViewById(R.id.task_confirm_textview))
          .setText(requestTaskStartData.getString("task_summary"));

      new Thread(new Runnable()
      {
        @Override
        public void run()
        {

            ... 
            // code retrieves an image file from server on separate thread
            // depending on results, call checkVerifyIdentity for additional processing and to show view
            ... 
            checkVerifyIdentity(bmp)

  }).start();

  ((TextView) findViewById(R.id.task_password_content_textview))
      .setText(requestTaskStartData.getString("task_password"));

}
catch ( JSONException e )
{
  ((TextView) findViewById(R.id.task_password_title_textview))
      .setVisibility(TextView.INVISIBLE);

  e.printStackTrace();
}

findViewById(R.id.task_confirm_button).setOnClickListener(
    new View.OnClickListener()
    {

      @Override
      public void onClick(View v)
      {
        setResult(RESULT_OK);
        finish();
      }
    });

findViewById(R.id.task_deny_button).setOnClickListener(
    new View.OnClickListener()
    {

      @Override
      public void onClick(View v)
      {

        setResult(RESULT_CANCELED);
        finish();
      }
    });

}  // end of StartTaskActivity.onCreate

    ...

// Check some parameters, and finish setting up view for display (runs on UI thread)
private void checkVerifyIdentity(final Bitmap bmp)
{
    final Context context = this;
    StartTaskActivity.this.runOnUiThread(new Runnable()
    {
      public void run()
      {
        if ( bmp != null )
        {
          ((ImageView) findViewById(R.id.task_confirm_imageview))
              .setImageBitmap(bmp);
        }
        if ( taskCheckpoints.length() > 0 )
        {
            ... // do some processing
        }
        else
        {
          setActivityVisible();  
        }
      }
    });
}

    ...
/**
* Sets the activity as visible. Should be called once all verifications are
* properly checked.
*/
private void setActivityVisible()
{
    this.setVisible(true);

}

      

The above line for setVisible is line 531 of StartTaskActivity, which ultimately calls NPE for Samsung G5, but not other devices / versions we can check. As reflected in the comments, the subsequent test on 4.4.4 the emulator is not able to replicate the error. So far, the error is observed only on the Samsung G5 itself with 4.4.4.

UPDATE:

Based on the time consuming process of a debug step displaying a good initial view (emulator 4.4.4) with a misrepresentation of the Samsung source, we narrowed down on the NPE cause. The app launches the NPE when it calls StartTaskActivity.setActivityVisible, which eventually starts up on a null object. Due to limitations in the tracing process, I can't say with certainty what this object is, but I'm assuming it's a window or a view. The line of code that throws it is "mDecor.setVisibility (View.VISIBLE)" (line 4355 in Samsung = line 4143 in the Activity.java emulator). So, technically, some part of the mDecor object is NULL.

We will probably use a different approach to achieve our goal as we cannot determine why Samsung v4.4.4 throws NPE when there is no other device / emulator, including Samsung v4.4.2. Perhaps, although this question will not be resolved, it may be useful to others in the future.

+3


source to share


1 answer


Considerable time has been spent isolating the root cause of this problem. We were unable to reproduce the NPE exception on any other device or emulator other than Samsung G5 (Sprint) running 4.4.4. It crashes when trying to use the setVisible method on an activity that started a background thread inside onCreate, and then runOnUiThread is started. It might have been bad practice that for some reason didn't bother other systems, but Samsung (at least) found it unacceptable.



We resolved this anyway by showing / hiding the activity-related view (using for example v.setVisibility(View.VISIBLE)

and some costly refactoring. As stated in the Android documentation, use Activity # setVisible with care.

+2


source







All Articles