我试图通过parseobject下载我的parseserver的一个映像,它在几秒钟后失败为“i/o失败”。我做了一些研究,发现“i/o失败”可能是连接到parseserver的问题。这就是为什么我试图在同一个脚本中只下载同一类的列名,而且效果很好。我的代码甚至响应找到一个对象。
这就是为什么我问自己,这是一个连接问题还是什么不同的,我不能明白。
我感谢你的帮助。这是我的密码
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.Image;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.parse.FindCallback;
import com.parse.GetDataCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import java.util.List;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
ImageView imageView = new ImageView(getApplicationContext());
imageView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
));
//TestDownload of String in column
ParseQuery<ParseObject> query = ParseQuery.getQuery("Image");
query.setLimit(1);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
for (ParseObject object : objects)
Log.i("Info Testname", object.getString("Name"));
}
}
});
//Download of Image(file)
ParseQuery<ParseObject> query1 = ParseQuery.getQuery("Image");
query1.whereEqualTo("Name", "testName");
query1.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
Log.i("findInBackground", "Retrieved " + objects.size() + " objects");
for (ParseObject object : objects) {
ParseFile file = (ParseFile) object.get("Image");
file.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException ex) {
if (ex == null) {
Bitmap bitmapImage = BitmapFactory.decodeByteArray(data, 0, data.length);
// Do something
Log.i("done", "done");
} else {
Log.i("info", ex.getMessage());
}
}
});
}
} else {
Log.i("info e", e.getMessage());
}
}
});
}
}
舱单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.downloadimagefromparse">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
logcat公司
2020-11-18 10:57:13.706 11155-11177/com.example.downloadimagefromparse I/OpenGLRenderer: Initialized EGL, version 1.4
2020-11-18 10:57:13.706 11155-11177/com.example.downloadimagefromparse D/OpenGLRenderer: Swap behavior 1
2020-11-18 10:57:13.706 11155-11177/com.example.downloadimagefromparse W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2020-11-18 10:57:13.706 11155-11177/com.example.downloadimagefromparse D/OpenGLRenderer: Swap behavior 0
2020-11-18 10:57:13.710 11155-11177/com.example.downloadimagefromparse D/EGL_emulation: eglCreateContext: 0xa9a05340: maj 2 min 0 rcv 2
2020-11-18 10:57:13.715 11155-11177/com.example.downloadimagefromparse D/EGL_emulation: eglMakeCurrent: 0xa9a05340: ver 2 0 (tinfo 0x9ff21ab0)
2020-11-18 10:57:13.728 11155-11177/com.example.downloadimagefromparse D/EGL_emulation: eglMakeCurrent: 0xa9a05340: ver 2 0 (tinfo 0x9ff21ab0)
2020-11-18 10:57:13.913 11155-11155/com.example.downloadimagefromparse I/findInBackground: Retrieved 1 objects
2020-11-18 10:57:13.916 11155-11155/com.example.downloadimagefromparse I/Info Testname: testName
2020-11-18 10:57:38.377 11155-11155/com.example.downloadimagefromparse I/info: i/o failure
1条答案
按热度按时间dvtswwa31#
您需要在应用程序类中初始化服务器连接,如《入门指南》中所述: