加载图像的ImageView的(Parse.com) [英] load an image in ImageView (Parse.com)
问题描述
重要提示:您可以使用:
ParseImageView
要轻松地处理这个过程。距今约2014年。希望它有助于通过谷歌到达这里的人它已经提供解析。
我试图加载从Parse.com的图像对象ID得心应手ImageView的。但不知何故,应用程序崩溃,而从解析获取的图像。我没能找到一个线索哪里出了问题。我有6 imageviews布局和现在我试图加载图像中只有1个的ImageView和其余的我指定的可绘制它们的来源。请帮助!
公共类登录扩展活动{
EditText上全名,移动电话号码,职业;
按钮保存;
ImageView的AD2,AD3,AD4,AD5,AD6;
HorizontalScrollView horizontalScrollView1;
私人ProgressDialog progressDialog;
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.userdata);
全名=(EditText上)findViewById(R.id.fullname);
移动电话号码=(EditText上)findViewById(R.id.mobile);
职业=(EditText上)findViewById(R.id.occupation);
节省=(按钮)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,,下载图片...,真正的);
//在Parse.com找到名为页脚之类的表
ParseQuery<的parseObject>查询=新ParseQuery<的parseObject>(页脚);
//从类找到OBJECTID
query.getInBackground(tNp607WyQD,新GetCallback<的parseObject>(){
公共无效做(的parseObject对象,ParseException的E){
// TODO自动生成方法存根
//找到名为ImageName,并设置列
//字符串
ParseFile文件对象=(ParseFile)object.get(镜像文件);
fileObject.getDataInBackground(新GetDataCallback(){
公共无效完成(byte []的数据,
ParseException的E){
如果(E == NULL){
Log.d(测试,
我们已经在数据获得的数据。);
//德$ C C的字节[]到$
//位图
BMP位= BitmapFactory.de codeByteArray(数据,0,data.length);
//从main.xml中的ImageView的
// ImageView的形象=(ImageView的)findViewById(R.id.ad1);
ImageView的AD1 =(ImageView的)findViewById(R.id.ad1);
//将位图到
// ImageView的
ad1.setImageBitmap(BMP);
//关闭进度对话框
progressDialog.dismiss();
} 其他 {
Log.d(测试,
有一个问题,下载数据。);
}
}
});
}
});
}}
版式文件:
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直
机器人:填充=10dip>
<! - 姓名标签 - >
<的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=全名
机器人:文字颜色=#372c24
工具:忽略=硬codedText/>
<的EditText
机器人:ID =@ + ID /全称
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginBottom =10dip
机器人:layout_marginTop =5dip
机器人:单线=真/>
<! - 电子邮件标签 - >
<的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=手机号码
机器人:文字颜色=#372c24
工具:忽略=硬codedText/>
<的EditText
机器人:ID =@ + ID /移动
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginBottom =10dip
机器人:layout_marginTop =5dip
机器人:单线=真
机器人:inputType =手机/>
<! - 密码标签 - >
<的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=职业
机器人:文字颜色=#372c24
工具:忽略=硬codedText/>
<的EditText
机器人:ID =@ + ID /职业
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =10dip
机器人:单线=真
工具:忽略=文本域/>
<! - 注册按钮 - >
<按钮
机器人:ID =@ + ID / btnSave
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =30dip
机器人:文本=保存
工具:忽略=硬codedText/>
< RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:后台=#FFFFFF>
<的LinearLayout
机器人:ID =@ + ID /页脚
机器人:方向=横向
机器人:layout_width =match_parent
机器人:layout_height =90dp
机器人:后台=#5C03
机器人:layout_alignParentBottom =真正的>
< ImageView的
机器人:ID =@ + ID / AD1
机器人:layout_width =90dp
机器人:layout_height =WRAP_CONTENT/>
< HorizontalScrollView
机器人:ID =@ + ID / horizontalScrollView1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
<的LinearLayout
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =match_parent
机器人:方向=横向>
< ImageView的
机器人:ID =@ + ID / AD2
机器人:layout_width =90dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_margin =3DP
机器人:SRC =@可绘制/ BG/>
< ImageView的
机器人:ID =@ + ID / AD3
机器人:layout_margin =3DP
机器人:SRC =@可绘制/ BG
机器人:layout_width =90dp
机器人:layout_height =WRAP_CONTENT/>
< ImageView的
机器人:ID =@ + ID / AD4
机器人:layout_margin =3DP
机器人:SRC =@可绘制/ BG
机器人:layout_width =90dp
机器人:layout_height =WRAP_CONTENT/>
< ImageView的
机器人:ID =@ + ID / AD5
机器人:layout_margin =3DP
机器人:layout_width =90dp
机器人:SRC =@可绘制/ BG
机器人:layout_height =WRAP_CONTENT/>
< ImageView的
机器人:ID =@ + ID / AD6
机器人:layout_margin =3DP
机器人:layout_width =90dp
机器人:SRC =@可绘制/ BG
机器人:layout_height =WRAP_CONTENT/>
< / LinearLayout中>
< / HorizontalScrollView>
< / LinearLayout中>
LogCat中:
01-18 20:31:07.290:E / AndroidRuntime(2420):未捕获的处理程序:螺纹主力退出,由于未捕获的异常
01-18 20:31:07.370:E / AndroidRuntime(2420):显示java.lang.NullPointerException
01-18 20:31:07.370:E / AndroidRuntime(2420):在com.mixorg.parsefooter.Login $ 1.done(Login.java:51)
01-18 20:31:07.370:E / AndroidRuntime(2420):在com.parse.GetCallback.internalDone(GetCallback.java:43)
01-18 20:31:07.370:E / AndroidRuntime(2420):在com.parse.GetCallback.internalDone(GetCallback.java:1)
01-18 20:31:07.370:E / AndroidRuntime(2420):在com.parse.Parse $ $ 6 1.运行(Parse.java:818)
01-18 20:31:07.370:E / AndroidRuntime(2420):在android.os.Handler.handleCallback(Handler.java:587)
01-18 20:31:07.370:E / AndroidRuntime(2420):在android.os.Handler.dispatchMessage(Handler.java:92)
01-18 20:31:07.370:E / AndroidRuntime(2420):在android.os.Looper.loop(Looper.java:123)
01-18 20:31:07.370:E / AndroidRuntime(2420):在android.app.ActivityThread.main(ActivityThread.java:4370)
01-18 20:31:07.370:E / AndroidRuntime(2420):在java.lang.reflect.Method.invokeNative(本机方法)
01-18 20:31:07.370:E / AndroidRuntime(2420):在java.lang.reflect.Method.invoke(Method.java:521)
01-18 20:31:07.370:E / AndroidRuntime(2420):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
01-18 20:31:07.370:E / AndroidRuntime(2420):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-18 20:31:07.370:E / AndroidRuntime(2420):在dalvik.system.NativeStart.main(本机方法)
01-18 20:31:07.430:E / SemcCheckin(2420):获取崩溃转储级别:java.io.FileNotFoundException:/数据/ SEMC-签入/故障转储
我解决它自己。其实这是一个可怕的错误不会在Android清单文件中添加两种权限。
<使用-权限的Android:名称=android.permission.INTERNET对/>
<使用-权限的Android:名称=android.permission.WRITE_EXTERNAL_STORAGE/>
谢谢大家! :)
important note: You can use:
ParseImageView
to handle this process easily. it's been available in Parse since about 2014. Hope it helps people arriving here via google.
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.");
}
}
});
}
});
}}
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
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" />
Thanks all !! :)
这篇关于加载图像的ImageView的(Parse.com)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!