将图像从Parse.com提取到horizo​​ntalscrollview

时间:2014-02-13 07:51:55

标签: android parse-platform

我正在尝试将图像放在水平滚动视图中并使其自动滚动。它成功从Drawable文件夹中获取图像并自动滚动。但是当我尝试从Parse.com获取图像时出现了问题。它被addImagesToView()所取代。这是我使用的代码:

public ImageLoader imgl;
List<ParseObject> ob;
int k=0;
private ImageView[] imgs = new ImageView[5];
String path = android.os.Environment.getExternalStorageDirectory()+"/slide";

在ImageLoader类中,我使用文件夹的“幻灯片”名称来保存从Parse表中获取的图像。

private String[] imageNameArray = {"Addiction1", "addiction2","addiction3", "addiction4", "addiction1", "addiction2"};

这些图像将被提取并存储在“slide”文件夹中。

@Override
public void onCreate(Bundle savedInstanceState) {
.
.
.
/** Adds the images to view. */
 public void addImagesToView(){
 try {

     Log.d("tag", "in addimagestoview");
    // Locate the class table named "Footer" in Parse.com
        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Footer");
            query.orderByDescending("updatedAt");
            query.whereEqualTo("Status", true);

            ob = query.find();
            for (ParseObject country : ob) {
                ParseFile image = (ParseFile) country.get("imageFile");
                imgl.DisplayImage(image.getUrl(), imgs[k]);
                k=k+1;
                Log.d("tag", "the urls are"+image.getUrl());
                                }
 } catch (ParseException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}   

    for (int i=0;i<imageNameArray.length;i++){
        final ImageView imageButton =   new ImageView(this);

这里我传递的文件夹名称来自外部存储器名称“slide”。

        int imageResourceId =getResources().getIdentifier(imageNameArray[i], "path",getPackageName());
     Drawable image  =  this.getResources().getDrawable(imageResourceId);
        imageButton.setBackgroundDrawable(image);
        imageButton.setTag(i);

Log Cat:

02-13 14:31:04.786: E/AndroidRuntime(12404): Uncaught handler: thread main exiting due to uncaught exception
02-13 14:31:04.796: E/AndroidRuntime(12404): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blessan/com.blessan.HorizonalSlideshow}: java.lang.NullPointerException
02-13 14:31:04.796: E/AndroidRuntime(12404):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2503)
02-13 14:31:04.796: E/AndroidRuntime(12404):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519)
02-13 14:31:04.796: E/AndroidRuntime(12404):    at android.app.ActivityThread.access$2200(ActivityThread.java:123)
02-13 14:31:04.796: E/AndroidRuntime(12404):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1870)
02-13 14:31:04.796: E/AndroidRuntime(12404):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-13 14:31:04.796: E/AndroidRuntime(12404):    at android.os.Looper.loop(Looper.java:123)
02-13 14:31:04.796: E/AndroidRuntime(12404):    at android.app.ActivityThread.main(ActivityThread.java:4370)
02-13 14:31:04.796: E/AndroidRuntime(12404):    at java.lang.reflect.Method.invokeNative(Native Method)
02-13 14:31:04.796: E/AndroidRuntime(12404):    at java.lang.reflect.Method.invoke(Method.java:521)
02-13 14:31:04.796: E/AndroidRuntime(12404):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-13 14:31:04.796: E/AndroidRuntime(12404):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-13 14:31:04.796: E/AndroidRuntime(12404):    at dalvik.system.NativeStart.main(Native Method)
02-13 14:31:04.796: E/AndroidRuntime(12404): Caused by: java.lang.NullPointerException
02-13 14:31:04.796: E/AndroidRuntime(12404):    at com.blessan.HorizonalSlideshow.addImagesToView(HorizonalSlideshow.java:129)
02-13 14:31:04.796: E/AndroidRuntime(12404):    at com.blessan.HorizonalSlideshow.onCreate(HorizonalSlideshow.java:65)
02-13 14:31:04.796: E/AndroidRuntime(12404):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-13 14:31:04.796: E/AndroidRuntime(12404):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2466)
02-13 14:31:04.796: E/AndroidRuntime(12404):    ... 11 more
02-13 14:31:04.806: E/SemcCheckin(12404): Get crash dump level : java.io.FileNotFoundException: /data/semc-checkin/crashdump

0 个答案:

没有答案