在ImageView中加载图像(Parse.com)

时间:2014-01-18 14:54:08

标签: android parse-platform

重要提示:您可以使用:

ParseImageView

轻松处理此过程。它自2014年左右开始在Parse上市。希望通过谷歌帮助人们到达这里。


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

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

2 个答案:

答案 0 :(得分:1)

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

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

全部谢谢!! :)

答案 1 :(得分:0)

根据logcat转储,您在Login.java的第51行上有一个null变量。调试代码,找出原因。