从绑定器存根实现中捕获运行时异常,当交换数组适配器中的数据时

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);
}
  }

当我在微调器中交换数据时,有一个错误:

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)

当我单击操作时,这会随机显示。


答案 1
W/Binder? Caught a RuntimeException from the binder stub implementation.
java.lang.NullPointerException

该消息以 开头,这意味着它只是一个警告。所以你可以忽略它。它的Android内部可忽略的问题。W/

这可能是警告的来源:https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/os/Binder.java#1054

如果您的代码工作正常,则应忽略这些警告。


答案 2

推荐