越来越"不幸的是已经停止"使用资源时出错 [英] getting "unfortunately has stopped" error when using resources

查看:150
本文介绍了越来越"不幸的是已经停止"使用资源时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得我不需要告诉我尝试,但我想告诉。有2 <字符串数组> 首先是机器人:项第二这些条目的值。当用户选择项我想获得该项目的价值。

另外我想问一下,当应用程序被打开,对话框运行。我想让它运行只是当用户以后选择一个项目。

 公共类选择扩展活动实现OnItemSelectedListener {    资源RSC = getResources();
    @燮pressLint(回收)
    最后TypedArray itemValues​​ = rsc.obtainTypedArray(R.array.selectValues​​);    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        // TODO自动生成方法存根
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.select);        微调形式=(微调)findViewById(R.id.sSelect);
        form.setOnItemSelectedListener(本);
    }    @覆盖
    公共无效onItemSelected(适配器视图<>的项目,查看ARG1,诠释排序,
            长ARG3){
        // TODO自动生成方法存根
        INT将selectedItem = itemValues​​.getInt(排序,1);
        对话D =新的对话框(本);
        TextView的T =新的TextView(本);
        t.se​​tText(将selectedItem);
        d.setContentView(T);
        d.setTitle(Sonuc!);
        d.show();    }    @覆盖
    公共无效onNothingSelected(适配器视图<>为arg0){
        // TODO自动生成方法存根    }}

当我使用资源问题出现。此外logcat的这里是。有什么问题,而这个问题的解决方案?

编辑:
另外这里是array.xml

 <资源>    <字符串数组名=选择>
        <项目>实力< /项目>
        <项目>大小和LT; /项目>
        <项目>脂肪损失< /项目>
    < /字符串数组>    <整型数组名=selectValues​​>
        <项目> 1 LT; /项目>
        <项目> 2'; /项目>
        <项目>第3版; /项目>
    < /整数数组>< /资源>


请来电的getResource在onCreate()方法。

I think I don't need to tell what I try to but I want to tell. There is 2 <string-array> first is for android:entries second for values of these entries. When user selects the item I want to get value of that item.

Also I want to ask, When application is opened, dialog run. I want to make it run just when after user select an item.

public class Select extends Activity implements OnItemSelectedListener{

    Resources rsc = getResources();
    @SuppressLint("Recycle")
    final TypedArray itemValues = rsc.obtainTypedArray(R.array.selectValues);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.select);

        Spinner form = (Spinner) findViewById(R.id.sSelect);
        form.setOnItemSelectedListener(this);
    }

    @Override
    public void onItemSelected(AdapterView<?> item, View arg1, int sort,
            long arg3) {
        // TODO Auto-generated method stub
        int selectedItem = itemValues.getInt(sort, 1);
        Dialog d = new Dialog(this);
        TextView t = new TextView(this);
        t.setText(selectedItem);
        d.setContentView(t);
        d.setTitle("Sonuc!");
        d.show();

    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }



}

Problem appear when I use Resources. Also logcat is here. What's the problem and solution of this problem?

EDIT: Also here is the array.xml

<resources>

    <string-array name="select">
        <item>Strength</item>
        <item>Size</item>
        <item>Fat loss</item>
    </string-array>

    <integer-array name="selectValues">
        <item>1</item>
        <item>2</item>
        <item>3</item>
    </integer-array>

</resources>

解决方案

please call getResource in onCreate() method.

这篇关于越来越&QUOT;不幸的是已经停止&QUOT;使用资源时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆