Caught a RuntimeException from the binder stub implementation when swap data in arrayadapter
Asked Answered
D

1

31
public class MainActivity extends AppCompatActivity {

     ArrayList<String> list = new ArrayList<>();

     ArrayAdapter<String> adapter;

     ArrayList<String> data1 = new ArrayList<>();

     ArrayList<String> data2 = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    for (int i = 0 ; i< 10 ;i++){
        data1.add(String.valueOf(i));
    }

    for (int i = 20; i < 30; i++){
        data2.add(String.valueOf(i));
    }

    Spinner spinner = (Spinner) findViewById(R.id.demo);
    adapter = new ArrayAdapter<>(this,android.R.layout.simple_dropdown_item_1line,list);
    spinner.setAdapter(adapter);
}

private void change(boolean which){
    if (which){
        list.clear();
        list.addAll(data1);

    }else{
        list.clear();
        list.addAll(data2);

    }
    adapter.notifyDataSetChanged();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_no) {
        change(true);
        return true;
    }else if (id == R.id.action_ok){
        change(false);
        return true;
    }

    return super.onOptionsItemSelected(item);
}
  }

when I swap the data in the spinner , there is a error :

08-25 11:51:59.630   29087-9866/me.aber.app.arrayapdapterdemo
D/dalvikvm? GC_FOR_ALLOC freed 2055K, 52% free 7378K/15192K, paused 24ms, total 30ms
08-25 11:52:01.923   29087-9866/me.aber.app.arrayapdapterdemo
W/Binder? Caught a RuntimeException from the binder stub implementation.
    java.lang.NullPointerException
at android.view.WindowManagerGlobal.dumpGfxInfo(WindowManagerGlobal.java:437)
at android.app.ActivityThread$ApplicationThread.dumpGfxInfo(ActivityThread.java:1021)
at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:550)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)

This appears randomly as I click the action.

Devotional answered 25/8, 2015 at 3:59 Comment(4)
Which sdk version are you using?Tableware
What exactly is your question? Are you trying to figure out what's causing this error, or how to address it?Galangal
I think Resource Id is of type long. So typecast it in Long rather than int, Second thing try to return false instead of calling the super callGarneau
Does this answer your question? https://mcmap.net/q/17345/-what-is-a-nullpointerexception-and-how-do-i-fix-it/113632Confiture
T
1
W/Binder? Caught a RuntimeException from the binder stub implementation.
java.lang.NullPointerException

The message starts with W/, which means its just a warning. So you can ignore it. Its Android's internal ignorable issue.

This may be the source of the warning: https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/os/Binder.java#1054

If your code works correctly then you should ignore these warnings.

Tague answered 7/5, 2020 at 20:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.