2

正如标题所说,当我尝试填充数组时,我的代码失败了,但它只适用于一项

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    int width=getWidth(this);
    int height=getHeight(this);
    String resolution= new String();
    tamanhos= new String[]{ "240x320","320x480","480x800","800x1280"};
    wallpapers= new String[]{ "fdonegrobrillo"};
    resolution=tamanhos[3]

    mImages=new int[wallpapers.length];
    Resources res= this.getResources();
    for(int i=0;i<wallpapers.length;i++){
    mImages[i]=res.getIdentifier(wallpapers[i]+resolution, "drawable",this.getPackageName());
}

我有所有相应的可绘制对象。当我尝试只使用一个项目时,应用程序可以工作,但如果我将另一个项目添加到壁纸数组,它会引发错误(致命信号 11(SIGSEGV))

我尝试使用这样的硬编码数组

mImages=new int[]{
        this.getResources().getIdentifier("fdobyn800x1280",
                  "drawable", this.getPackageName())

};

我工作,但是当我添加另一个项目时它是一样的

mImages=new int[]{
        this.getResources().getIdentifier("fdobyn800x1280",
                  "drawable", this.getPackageName()),
        this.getResources().getIdentifier("fdonegrobrillo800x1280",
                          "drawable", this.getPackageName())

};
4

1 回答 1

0

可能是不在壁纸阵列中的问题。它的代码工作正常,不会引发任何错误。

package com.example;
    import android.app.Activity;
    import android.content.res.Resources;
    import android.os.Bundle;

    public class MyActivity extends Activity {

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            //int width=getWidth(this);
            //int height=getHeight(this);
            String resolution= new String();
            String[] tamanhos= new String[]{"240x320","320x480","480x800","800x1280"};
            String[] wallpapers= new String[]{"fdonegrobrillo", "2", "3"};
            resolution=tamanhos[3];

            int[] mImages=new int[wallpapers.length];
            Resources res= this.getResources();
            for(int i=0;i<wallpapers.length;i++){
                mImages[i]=res.getIdentifier(wallpapers[i]+resolution, "drawable",this.getPackageName());
            }
        }
    }
于 2012-12-07T18:40:12.313 回答