Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java BitmapFactory.decodeStream导致:D/skia:---无法创建带有消息';未实施';_Java_Android_Url_Bitmapfactory - Fatal编程技术网

Java BitmapFactory.decodeStream导致:D/skia:---无法创建带有消息';未实施';

Java BitmapFactory.decodeStream导致:D/skia:---无法创建带有消息';未实施';,java,android,url,bitmapfactory,Java,Android,Url,Bitmapfactory,我试图通过使用创建位图从URL下载图像 bitmapFactory.decodeStream(InputStream)然后imageView.setImageBitmap(bitmap),但我总是遇到以下错误: D/skia:---无法创建带有消息的图像解码器 “未执行”。包com.example.flickrapp 这是我的密码: 导入语句将转到此处 public class MainActivity extends AppCompatActivity { @Override protect

我试图通过使用创建位图从URL下载图像
bitmapFactory.decodeStream(InputStream)
然后
imageView.setImageBitmap(bitmap)
,但我总是遇到以下错误:

D/skia:---无法创建带有消息的图像解码器

“未执行”。包com.example.flickrapp

这是我的密码:

导入语句将转到此处

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
protected void onStart() {
    super.onStart();
    Button b = (Button)findViewById(R.id.getanimage);
    b.setOnClickListener(new GetImageOnClickListener() {
        @Override
        public void onClick(View v) {
            super.onClick(v);
        }
    });
}

public class GetImageOnClickListener implements View.OnClickListener {
    @Override
    public void onClick(View v) {
        AsyncFlickrJSONData imagesData = new AsyncFlickrJSONData();
        imagesData.execute("https://www.flickr.com/services/feeds/photos_public.gne?tags=trees&format=json");
    }
}

public class AsyncFlickrJSONData extends AsyncTask<String, Void, JSONObject> {

    @Override
    protected JSONObject doInBackground(String... strings) {
        String flickrUrl = strings[0];
        JSONObject jsonFlickr = null;
        URL url = null;
        try {
            url = new URL(flickrUrl);
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            try {
                InputStream in = new BufferedInputStream(urlConnection.getInputStream());
                String s1 = readStream(in);
                int lengthS = s1.length();
                String s = (String) s1.subSequence(15, lengthS-1);
                jsonFlickr = new JSONObject(s);
            } finally {
                urlConnection.disconnect();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException | JSONException e) {
            e.printStackTrace();
        }
        return jsonFlickr;
    }

    @Override
    protected void onPostExecute(JSONObject jsonFlickr) {
        super.onPostExecute(jsonFlickr);
        try {
            String firstUrl = jsonFlickr.getJSONArray("items").getJSONObject(0).getString("link");
            AsyncBitmapDownloader firstAsyncImage = new AsyncBitmapDownloader();
            firstAsyncImage.execute(firstUrl);
            Log.i("JFL", firstUrl);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    private String readStream(InputStream in) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuilder sb = new StringBuilder();

        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
        } catch (IOException e) {
            Log.e(TAG, "IOException", e);
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                Log.e(TAG, "IOException", e);
            }
        }
        return sb.toString();
    }
}

public class AsyncBitmapDownloader extends AsyncTask<String, Void, Bitmap> {

    ImageView firstImage = (ImageView) findViewById(R.id.image);

    @Override
    protected Bitmap doInBackground(String... strings) {
        String imageUrl = strings[0];
        Bitmap bm = null;
        URL url = null;
        try {
            url = new URL(imageUrl);
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            try {
                InputStream in = new BufferedInputStream(urlConnection.getInputStream());
                bm = BitmapFactory.decodeStream(in);
            } finally {
                urlConnection.disconnect();
            }
        } catch(IOException e){
                e.printStackTrace();
        }
        return bm;
    }

    @Override
    protected void onPostExecute(Bitmap bitmap) {
        super.onPostExecute(bitmap);
        firstImage.setImageBitmap(bitmap);
    }
}
public类MainActivity扩展了AppCompatActivity{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@凌驾
受保护的void onStart(){
super.onStart();
按钮b=(按钮)findViewById(R.id.getanimage);
b、 setOnClickListener(新的GetImageOnClickListener(){
@凌驾
公共void onClick(视图v){
super.onClick(v);
}
});
}
公共类GetImageOnClickListener实现View.OnClickListener{
@凌驾
公共void onClick(视图v){
AsyncFlickrJSONData imagesData=新的AsyncFlickrJSONData();
imagesData.execute(“https://www.flickr.com/services/feeds/photos_public.gne?tags=trees&format=json");
}
}
公共类AsyncFlickrJSONData扩展AsyncTask{
@凌驾
受保护的JSONObject doInBackground(字符串…字符串){
String flickrl=strings[0];
JSONObject jsonFlickr=null;
URL=null;
试一试{
url=新url(flickrUrl);
HttpURLConnection urlConnection=(HttpURLConnection)url.openConnection();
试一试{
InputStream in=new BufferedInputStream(urlConnection.getInputStream());
字符串s1=读取流(in);
int length=s1.length();
字符串s=(字符串)s1.子序列(15,长度-1);
jsonFlickr=新的JSONObject;
}最后{
urlConnection.disconnect();
}
}捕获(格式错误){
e、 printStackTrace();
}捕获(IOException | JSONException e){
e、 printStackTrace();
}
返回jsonFlickr;
}
@凌驾
受保护的void onPostExecute(JSONObject jsonFlickr){
onPostExecute(jsonFlickr);
试一试{
String firstUrl=jsonFlickr.getJSONArray(“items”).getJSONObject(0.getString(“link”);
AsyncBitmapDownloader firstAsyncImage=新的AsyncBitmapDownloader();
firstAsyncImage.execute(firstUrl);
Log.i(“JFL”,firstUrl);
}捕获(JSONException e){
e、 printStackTrace();
}
}
私有字符串读取流(输入流输入){
BufferedReader reader=新的BufferedReader(新的InputStreamReader(in));
StringBuilder sb=新的StringBuilder();
字符串行=null;
试一试{
而((line=reader.readLine())!=null){
sb.追加(第+行“\n”);
}
}捕获(IOE异常){
Log.e(标签“IOException”,e);
}最后{
试一试{
in.close();
}捕获(IOE异常){
Log.e(标签“IOException”,e);
}
}
使某人返回字符串();
}
}
公共类AsyncBitmapDownloader扩展了AsyncTask{
ImageView firstImage=(ImageView)findViewById(R.id.image);
@凌驾
受保护位图doInBackground(字符串…字符串){
字符串imageUrl=strings[0];
位图bm=null;
URL=null;
试一试{
url=新url(imageUrl);
HttpURLConnection urlConnection=(HttpURLConnection)url.openConnection();
试一试{
InputStream in=new BufferedInputStream(urlConnection.getInputStream());
bm=BitmapFactory.decodeStream(in);
}最后{
urlConnection.disconnect();
}
}捕获(IOE异常){
e、 printStackTrace();
}
返回bm;
}
@凌驾
受保护的void onPostExecute(位图){
onPostExecute(位图);
setImageBitmap(位图);
}
}
}

欢迎提出任何建议或想法:)