我在我的一个值的文件夹中创建了一个数组列表,现在当我想通过从源文件夹中检索它来调整它时,它表示nullPointerExeption:
spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this,R.array.worker,android.R.layout.simple_list_item_1);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
LogCat中的消息:
Caused by: android.content.res.Resources$NotFoundException: String array resource ID #0x7f090001 at android.content.res.Resources.getStringArray(Resources.java:527) at com.example.hay.myapplication.UserCreatingActivity.onCreate(UserCreatingActivity.java:46) at android.app.Activity.performCreate(Activity.java:5990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:227
答案 0 :(得分:0)
尝试给ArrayAdapter一个类型:
ArrayAdapter<String> adapter = ArrayAdapter.createFromResource(this, R.array.worker, android.R.layout.simple_spinner_item);
答案 1 :(得分:0)
尝试翻转createFromRessource
中的最后两个参数:
替换:
ArrayAdapter adapter = ArrayAdapter.createFromResource(this,R.array.worker,android.R.layout.simple_list_item_1);
人:
ArrayAdapter<String> adapter = ArrayAdapter.createFromResource(this, android.R.layout.simple_list_item_1, R.array.worker);
在您的代码中:
spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> adapter = ArrayAdapter.createFromResource(this, android.R.layout.simple_list_item_1, R.array.worker);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
答案 2 :(得分:0)
因为你有例外:
`Caused by: android.content.res.Resources$NotFoundException: String array resource ID #0x7f090001 at
我发现您的问题是createFromResource()
方法中的最后一个值:
ArrayAdapter adapter = ArrayAdapter.createFromResource(this,R.array.worker,android.R.layout.simple_list_item_1);
最后一个值必须是数组:
ArrayAdapter adapter = ArrayAdapter.createFromResource(this,android.R.layout.simple_list_item_1,R.array.worker);
答案 3 :(得分:-1)
更改
attr.xml
目录
来自
...\app\src\main\res\values-w820dp
到
...\app\src\main\res\values