Upload Image to ImageView (Parse.com)

important note: you can use:

ParseImageView

easy to handle this process. It has been available at Parse since 2014. Hope this helps people arriving here via Google.


I am trying to upload an image from Parse.com with an object identifier convenient in ImageView. But for some reason, the application crashes, choosing an image from parsing. I can not find the key where the problem is. I have 6 images in the layout, and at the moment I'm trying to upload an image in only 1 ImageView, and for the rest I indicate 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.");
                                    }
                                }
                            });
                }
            });
}}

Layout File:

<?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
+4
source share
2 answers

. android.

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

!:)

+1

logcat 51 Login.java. , .

0

All Articles