gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 10:47:12 25 4
gpt4 key购买 nike

重要提示:您可以使用:

解析 ImageView

轻松处理这个过程。它从 2014 年左右开始在 Parse 中可用。希望它能帮助人们通过谷歌到达这里。


我正在尝试从 Parse.com 加载图像,并在 ImageView 中使用方便的对象 ID。但是不知何故,应用程序在从解析中获取图像时崩溃了。我找不到问题出在哪里的线索。我在布局中有 6 个 ImageView ,现在我尝试仅在 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>

日志:

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 list 文件中添加两个权限是一个可怕的错误。 :

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

谢谢大家!! :)

关于android - 在 ImageView (Parse.com) 中加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21205693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com