views:

130

answers:

2

Am I missing something here?

I follow the instructions exactly on this page (and some of the other tutorials) but they always seem to be missing some key information as they dont work out of the box

I added a bunch of packages that seemed like were missing, but now I'm stuck.

http://developer.android.com/resources/tutorials/views/hello-gridview.html

Description Resource Path Location Type Conversion to Dalvik format failed with error 1 HelloGrid Unknown Android Packaging Problem

And a whole bunch of these for each of the drawable.sample_* references

Description Resource Path Location Type R.drawable.sample_0 cannot be resolved ImageAdapter.java /HelloGrid/src/com/example/ImageAdapter line 51 Java Problem

package com.example.HelloGrid;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.example.ImageAdapter.ImageAdapter;

public class HelloGrid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new ImageAdapter(this));

        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Toast.makeText(HelloGrid.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }
}

package com.example.ImageAdapter;
import android.R;
import android.R.drawable;
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 getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8, 8, 8, 8);
        } else {
            imageView = (ImageView) convertView;
        }

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

    // 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
    };
}

As you can see I have all the images loaded in the /drawable directory alt text

+1  A: 

It looks like the tutorials are missing some of the package information, but if you're using eclipse it should handle most of that for you.

janice
Thanks for being helpful. None of the answers really solved my problem. I even found that i was not the only one with this issue.
codeninja
+1  A: 

Description Resource Path Location Type R.drawable.sample_0 cannot be resolved ImageAdapter.java /HelloGrid/src/com/example/ImageAdapter line 51 Java Problem

You are missing your drawable resources. That was covered in step #2 in the instructions supplied in the tutorial.

CommonsWare
btw http://meta.stackoverflow.com/questions/9953/could-we-please-be-a-bit-nicer-to-the-noobs
codeninja
@codeninja: The error you cite comes from Android not being able to find the drawable resources. This is not an assumption -- this is a fact. The JPEG files in question are in the ZIP file referenced from step #2 in the instructions. This is not an assumption -- this is a fact. Now, step #2 is not particularly well-written, and they stuck a .DS_Store file in the ZIP archive for no good reason. Try doing a Project|Clean to force a rebuild, and make sure you didn't wind up with the .DS_Store file in there as well, as Android won't like that.
CommonsWare
@codeninja: I also notice you elected to delete a comment of yours.
CommonsWare
It cant find the resources, fine. I unzipped the zip file they provided and I dropped the jpegs into my project in the directory they specified (you can see this in my screen shot). I've done a clean build several times and quite frankly you are not being helpful at all here...Since you guys prefer to rag on me rather than help me, I was going to repost it. I really dont know what level of DETAIL you people need in order to help with a question. Voting me down for whatever stupid reasons. I tried to give all the info I felt was necessary.
codeninja
@codeninja: Check to see if there are other error messages besides the ones you have in boldface. It may be that the drawables are fine, but there is something else causing `aapt` (part of the build process) to fail to create your `R.java` file (where all the `R.` constants come from). For example, a malformed layout file will result in another error in your Eclipse console and will cause `R.java` to not be created.
CommonsWare
Yes, what CommonsWare said. Make sure something isn't up in your xml layout file that's causing your R.java not to be created.
ShadowGod