Java 访问阵列时出错

Java 访问阵列时出错,java,android,gridview,arraylist,Java,Android,Gridview,Arraylist,Noob android开发人员正在尝试使用保存在我的服务器上的缩略图创建图库: 我试图在ImageAdapter中使用ArrayList,以便在创建缩略图列表循环时可以引用数组值。我的eclipse包可供下载,因为我可能没有正确解释这一点。当我尝试在数组中引用我的“thumb”值时,我在尝试创建我的“mThumbIds”时会遇到一个未定义的错误以及一个语法错误 我不知道为什么我很难理解这一点 showtumb.java: package com.flash_tattoo; import an

Noob android开发人员正在尝试使用保存在我的服务器上的缩略图创建图库:

我试图在ImageAdapter中使用ArrayList,以便在创建缩略图列表循环时可以引用数组值。我的eclipse包可供下载,因为我可能没有正确解释这一点。当我尝试在数组中引用我的“thumb”值时,我在尝试创建我的“mThumbIds”时会遇到一个未定义的错误以及一个语法错误

我不知道为什么我很难理解这一点

showtumb.java:

package com.flash_tattoo;

import android.os.Bundle;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;

public class showThumb extends Activity{



    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gridlayout);

         Bundle bundle = getIntent().getExtras();
         String jsonData = bundle.getString("jsonData");


         JSONArray jsonArray = null;
        try {
            jsonArray = new JSONArray(jsonData);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        ArrayList<image_data> myJSONArray = new ArrayList<image_data>();

         for(int i=0;i<jsonArray.length();i++)
            {    

                 JSONObject json_data = null;

                try {
                    json_data = jsonArray.getJSONObject(i);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                 try {
                    image_data.id =  json_data.getInt("id");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                 try {
                    image_data.name = json_data.getString("name");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                 try {
                    image_data.thumb = json_data.getString("thumb");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                 try {
                    image_data.path = json_data.getString("path");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                myJSONArray.add(new image_data());
            }


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

        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Toast.makeText(showThumb.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }
}
package com.flash_纹身;
导入android.os.Bundle;
导入android.widget.AdapterView.OnItemClickListener;
导入android.widget.GridView;
导入java.util.ArrayList;
导入java.util.List;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入android.app.Activity;
导入android.content.ActivityNotFoundException;
导入android.content.Intent;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.*;
公共类showtumb扩展活动{
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.gridlayout);
Bundle Bundle=getIntent().getExtras();
String jsonData=bundle.getString(“jsonData”);
JSONArray JSONArray=null;
试一试{
jsonArray=新jsonArray(jsonData);
}捕获(JSONException e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
ArrayList myJSONArray=新的ArrayList();

对于(inti=0;i您有一个Integer[]类型的私有字段mThumbIds,并且您试图以内联方式初始化它,但是您没有这样做,因为您有一个带有语句的静态块{}

我想说你只需要声明:

private Integer[] mThumbIds;

然后,您可以在构造函数中填充数组。

我现在将对此进行测试。感谢您的反馈+1
private Integer[] mThumbIds;