在 ImageView (Parse.com) 中加载图像 [英] load an image in ImageView (Parse.com)

查看:13
本文介绍了在 ImageView (Parse.com) 中加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重要提示:您可以使用:

轻松处理此过程.自 2014 年左右开始在 Parse 中可用.希望它可以帮助人们通过谷歌到达这里.

to handle this process easily. it's been available in Parse since about 2014. Hope it helps people arriving here via google.

我正在尝试从 Parse.com 加载图像,并在 ImageView 中使用方便的对象 ID.但是不知何故,应用程序在从解析中获取图像时崩溃了.我无法找到问题出在哪里的线索.我在布局中有 6 个图像视图,现在我只尝试在 1 个 ImageView 中加载图像,其余的我从 Drawable 中指定它们的源.请帮忙!!

I am trying to load an image from Parse.com with object id handy in ImageView. But somehow app is crashing while fetching the image from parse. I'm not able to find a clue where is the problem. I have 6 imageviews in layout and for now I'm trying to load image in only 1 ImageView and for the rest I'm specifying their source from Drawable. Please help !!

public class Login extends Activity {
EditText fullname, mobilenumber, occupation;
 Button save;
 ImageView ad2,ad3,ad4,ad5,ad6;
 HorizontalScrollView horizontalScrollView1;
    private ProgressDialog progressDialog;
public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.userdata);
     fullname = (EditText) findViewById(R.id.fullname) ;
     mobilenumber = (EditText) findViewById(R.id.mobile) ;
    occupation = (EditText) findViewById(R.id.occupation) ;
     save=(Button) findViewById(R.id.btnSave);      
    horizontalScrollView1=(HorizontalScrollView) findViewById(R.id.horizontalScrollView1);
    //ad1=(ImageView) findViewById(R.id.ad1);
    ad2=(ImageView) findViewById(R.id.ad2);
    ad3=(ImageView) findViewById(R.id.ad3);
    ad4=(ImageView) findViewById(R.id.ad4);
    ad5=(ImageView) findViewById(R.id.ad5);
    ad6=(ImageView) findViewById(R.id.ad6);
     progressDialog = ProgressDialog.show(Login.this, "","Downloading Image...", true);
    // Locate the class table named "Footer" in Parse.com
    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Footer");
    // Locate the objectId from the class
    query.getInBackground("tNp607WyQD", new GetCallback<ParseObject>() {
                public void done(ParseObject object,ParseException e) {
                    // TODO Auto-generated method stub
                    // Locate the column named "ImageName" and set
                    // the string
                    ParseFile fileObject = (ParseFile) object.get("imageFile");
                    fileObject.getDataInBackground(new GetDataCallback() {
                                public void done(byte[] data,
                                        ParseException e) {
                                    if (e == null) {
                                        Log.d("test",
                                                "We've got data in data.");
                                        // Decode the Byte[] into
                                        // Bitmap
                                        Bitmap bmp = BitmapFactory.decodeByteArray(data, 0,data.length);
                                        // Get the ImageView from main.xml
                                        //ImageView image = (ImageView) findViewById(R.id.ad1);
                                        ImageView ad1=(ImageView) findViewById(R.id.ad1);
                                        // Set the Bitmap into the
                                        // ImageView
                                        ad1.setImageBitmap(bmp);
                                        // Close progress dialog
                                        progressDialog.dismiss();
                                    } else {
                                        Log.d("test",
                                                "There was a problem downloading the data.");
                                    }
                                }
                            });
                }
            });
}}

布局文件:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dip" >

<!-- Full Name Label -->

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Full Name"
    android:textColor="#372c24"
    tools:ignore="HardcodedText" />

<EditText
    android:id="@+id/fullname"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dip"
    android:layout_marginTop="5dip"
    android:singleLine="true" />
<!-- Email Label -->

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Mobile number"
    android:textColor="#372c24"
    tools:ignore="HardcodedText" />

<EditText
    android:id="@+id/mobile"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dip"
    android:layout_marginTop="5dip"
    android:singleLine="true"
    android:inputType="phone" />
    

<!-- Password Label -->

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Occupation"
    android:textColor="#372c24"
    tools:ignore="HardcodedText" />

<EditText
    android:id="@+id/occupation"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dip"
    android:singleLine="true"
    tools:ignore="TextFields" />

<!-- Register Button -->

<Button
    android:id="@+id/btnSave"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dip"
    android:text="Save"
    tools:ignore="HardcodedText" />
<RelativeLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"     
android:background="#ffffff">
  <LinearLayout
    android:id="@+id/footer"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="90dp" 
    android:background="#5C03"
    android:layout_alignParentBottom="true">    
 <ImageView
 android:id="@+id/ad1"
 android:layout_width="90dp"
 android:layout_height="wrap_content" />
<HorizontalScrollView
 android:id="@+id/horizontalScrollView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" >
 <LinearLayout
 android:layout_width="wrap_content"
 android:layout_height="match_parent"
 android:orientation="horizontal" >
 <ImageView
  android:id="@+id/ad2"
  android:layout_width="90dp"
  android:layout_height="wrap_content"
  android:layout_margin="3dp"
  android:src="@drawable/bg" />
    <ImageView
    android:id="@+id/ad3"
    android:layout_margin="3dp"
    android:src="@drawable/bg"
    android:layout_width="90dp"
    android:layout_height="wrap_content"/>
    <ImageView
    android:id="@+id/ad4"
    android:layout_margin="3dp"
    android:src="@drawable/bg"
    android:layout_width="90dp"
    android:layout_height="wrap_content" />
    <ImageView
    android:id="@+id/ad5"
    android:layout_margin="3dp"
    android:layout_width="90dp"
    android:src="@drawable/bg"
    android:layout_height="wrap_content" />
    <ImageView
    android:id="@+id/ad6"
    android:layout_margin="3dp"
    android:layout_width="90dp"
    android:src="@drawable/bg"
    android:layout_height="wrap_content" />
    </LinearLayout>
</HorizontalScrollView>
</LinearLayout>

LogCat:

01-18 20:31:07.290: E/AndroidRuntime(2420): Uncaught handler: thread main exiting due to uncaught exception
01-18 20:31:07.370: E/AndroidRuntime(2420): java.lang.NullPointerException
01-18 20:31:07.370: E/AndroidRuntime(2420):     at com.mixorg.parsefooter.Login$1.done(Login.java:51)
01-18 20:31:07.370: E/AndroidRuntime(2420):     at com.parse.GetCallback.internalDone(GetCallback.java:43)
01-18 20:31:07.370: E/AndroidRuntime(2420):     at com.parse.GetCallback.internalDone(GetCallback.java:1)
01-18 20:31:07.370: E/AndroidRuntime(2420):     at com.parse.Parse$6$1.run(Parse.java:818)
01-18 20:31:07.370: E/AndroidRuntime(2420):     at android.os.Handler.handleCallback(Handler.java:587)
01-18 20:31:07.370: E/AndroidRuntime(2420):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-18 20:31:07.370: E/AndroidRuntime(2420):     at android.os.Looper.loop(Looper.java:123)
01-18 20:31:07.370: E/AndroidRuntime(2420):     at android.app.ActivityThread.main(ActivityThread.java:4370)
01-18 20:31:07.370: E/AndroidRuntime(2420):     at java.lang.reflect.Method.invokeNative(Native Method)
01-18 20:31:07.370: E/AndroidRuntime(2420):     at java.lang.reflect.Method.invoke(Method.java:521)
01-18 20:31:07.370: E/AndroidRuntime(2420):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-18 20:31:07.370: E/AndroidRuntime(2420):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-18 20:31:07.370: E/AndroidRuntime(2420):     at dalvik.system.NativeStart.main(Native Method)
01-18 20:31:07.430: E/SemcCheckin(2420): Get crash dump level : java.io.FileNotFoundException: /data/semc-checkin/crashdump

推荐答案

我自己解决了.实际上,不在 android manifest 文件中添加两个权限是一个可怕的错误.:

I resolved it myself. Actually it was a terrible mistake not to adding two permissions in android manifest file. :

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

谢谢大家!!:)

这篇关于在 ImageView (Parse.com) 中加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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