2011-12-15 54 views
0

我试图通过Java,Eclipse开发Android应用程序。我想使用这个exampleAndroid编程错误

我的活动:

package grid.View; 

import android.content.Context; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseAdapter; 
import android.widget.GridView; 
import android.widget.ImageView; 

public class ImageAdapter extends BaseAdapter { 
    private Context mContext; 

    public ImageAdapter(Context c) { 
     mContext = c; 
    } 

    public int getCount() { 
     return mThumbIds.length; 
    } 

    public Object getItem(int position) { 
     return null; 
    } 

    public long getItemId(int position) { 
     return 0; 
    } 

    // create a new ImageView for each item referenced by the Adapter 
    public View getVieww(int position, View convertView, ViewGroup parent) { 
     ImageView imageVieww; 
     if (convertView == null) { // if it's not recycled, initialize some attributes 
      imageVieww = new ImageView(mContext); 
      imageVieww.setLayoutParams(new GridView.LayoutParams(85, 85)); 
      imageVieww.setScaleType(ImageView.ScaleType.CENTER_CROP); 
      imageVieww.setPadding(8, 8, 8, 8); 
     } else { 
      imageVieww = (ImageView) convertView; 
     } 

     imageVieww.setImageResource(mThumbIds[position]); 
     return imageVieww; 
    } 

    // references to our images 
    private Integer[] mThumbIds = { 
      R.drawable.sample_2, R.drawable.sample_3, 
      R.drawable.sample_4, R.drawable.sample_5, 
      R.drawable.sample_6, R.drawable.sample_7, 
      R.drawable.sample_0, R.drawable.sample_1, 
      R.drawable.sample_2, R.drawable.sample_3, 
      R.drawable.sample_4, R.drawable.sample_5, 
      R.drawable.sample_6, R.drawable.sample_7, 
      R.drawable.sample_0, R.drawable.sample_1, 
      R.drawable.sample_2, R.drawable.sample_3, 
      R.drawable.sample_4, R.drawable.sample_5, 
      R.drawable.sample_6, R.drawable.sample_7 
    }; 

    public View getView(int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 
     return null; 
    } 
} 

我有这样的错误,所有这些 “样本”:

sample_2不能得到解决或无法在现场

我是什么应该做的? :S

谢谢!

+0

它指向哪条线?你可能需要更具体一些,因为它可能是很多事情。 – 2011-12-15 16:17:14

回答

1

R.drawable.sample_2在您的可绘制文件夹中引用名为“sample_2”的图像。 如果显示此错误,图像在您的可绘制文件夹(s)中不可用(缺少,不同的名称?),或者您尚未导入R.java文件。

从外观上看,您还没有下载示例中描述的图像,并将它们放在您的drawables文件夹中。

2

你应该在你的文件夹绘制名为sample_0.png图像0​​ Android的SDK会检测到它们,并产生变量R.drawable.sample_X(X - 0〜7)供您使用。

+0

是的,谢谢,这解决了这个问题。现在我可以编译它,但应用程序崩溃。 (FORCE KILL BLAH BLAH BLAH ..):/ – 2011-12-15 16:27:20

1

这意味着drawables文件夹中没有这样的资源。要么你必须在那里添加它或不再使用它。

如果你真的有它,然后尝试清洁&再次建立你的项目。

希望这会有所帮助!