如何存储抽拉以阵列 [英] How to store drawable in an array

查看:132
本文介绍了如何存储抽拉以阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想下载一些图片,并想将其存储在一个数组绘制。于是,我就宣告绘制array.But它,当我访问数组返回我空指针例外。

I want to download a bunch of images and would like to store it as drawable in an array. So I tried declaring a drawable array.But it returns me nullPointer exception when I access that array.

我的问题是,如何声明数组类型为绘制?

My question is, how to declare an array type as drawable ?

推荐答案

可绘制的数组定义应该像:

an array of drawables would be declared like:

int numDrawables = 10;
Drawable[] drawableArray = new Drawable[numDrawables];

要填充数组:

for(int i = 0; i < numDrawables; i++){
    // get a drawable from somewhere
    Drawable drawable = new Drawable();
    drawableArray[i] = drawable;
}

要访问数组:

Drawable aDrawable = drawableArray[0];

这是基本的Java,如果您收到空指针异常,你正在做的事情是错误的。

This is basic java, If you are getting null pointer exceptions, you are doing something wrong.

这篇关于如何存储抽拉以阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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