本文介绍了适配器一个微调使得nullPointerExeption的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在价值的文件夹中的一种制成一个数组列表,现在,当我想从源文件检索以使其适应微调它说nullPointerExeption:

  =微调(微调)findViewById(R.id.spinner);    ArrayAdapter适配器= ArrayAdapter.createFromResource(这一点,R.array.worker,android.R.layout.simple_list_item_1);
    spinner.setAdapter(适配器);
    spinner.setOnItemSelectedListener(本);

在LogCat中消息:

 产生的原因:android.content.res.Resources $ NotFoundException:在COM在android.content.res.Resources.getStringArray(Resources.java:527)String数组资源ID#0x7f090001 .example.hay.myapplication.UserCreatingActivity.onCreate(UserCreatingActivity的.java:46)在android.app.Activity.performCreate(Activity.java:5990)在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)的机器人.app.ActivityThread.performLaunchActivity(ActivityThread.java:227


解决方案

试着翻动 createFromRessource 最后两个参数:

替换为:

  ArrayAdapter适配器= ArrayAdapter.createFromResource(这一点,R.array.worker,android.R.layout.simple_list_item_1);

方式:

  ArrayAdapter<串GT;适配器= ArrayAdapter.createFromResource(这一点,android.R.layout.simple_list_item_1,R.array.worker);

在您的code:

  =微调(微调)findViewById(R.id.spinner);    ArrayAdapter<串GT;适配器= ArrayAdapter.createFromResource(这一点,android.R.layout.simple_list_item_1,R.array.worker);
    spinner.setAdapter(适配器);
    spinner.setOnItemSelectedListener(本);

I made an array list in one of my value's folder, now when i want to adapt it to the spinner by retrieving it from the source folder it says 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);

Messages in 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
解决方案

Try to flip the two last parameters in createFromRessource:

Replace:

ArrayAdapter adapter = ArrayAdapter.createFromResource(this,R.array.worker,android.R.layout.simple_list_item_1);

By:

ArrayAdapter<String> adapter = ArrayAdapter.createFromResource(this, android.R.layout.simple_list_item_1, R.array.worker);

In your code:

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

这篇关于适配器一个微调使得nullPointerExeption的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 21:23