Android显示图像 - Surface无效

时间:2015-06-30 19:17:58

标签: java android

06-30 11:59:40.153  27202-27202/com.downloader.newlevel.krim.newleveldownloader E/ViewSystem﹕ ViewRootImpl #2 Surface is not valid.
06-30 11:59:41.114  27202-27216/com.downloader.newlevel.krim.newleveldownloader E/Error﹕ https://photos-4.dropbox.com/t/2/AAAxrzwz2B32dmtjRTNlT1vhQfVd5JuglMkbVV_m8BRkLg/12/145533347/png/32x32/1/_/1/2/Hourglass%20Addon%20by%20Redstone.png/CKPTskUgASACIAMgBCAFIAYgBygBKAI/Jpa4t4f3nMDieOULhjrmus_8mVpqVO37XxrQYkzMoSo?size=800x600&size_mode=2
06-30 12:00:57.429  27202-27202/com.downloader.newlevel.krim.newleveldownloader E/ViewSystem﹕ ViewRootImpl #2 Surface is not valid.
06-30 12:00:58.219  27202-27755/com.downloader.newlevel.krim.newleveldownloader E/Error﹕ https://photos-4.dropbox.com/t/2/AAAxrzwz2B32dmtjRTNlT1vhQfVd5JuglMkbVV_m8BRkLg/12/145533347/png/32x32/1/_/1/2/Hourglass%20Addon%20by%20Redstone.png/CKPTskUgASACIAMgBCAFIAYgBygBKAI/Jpa4t4f3nMDieOULhjrmus_8mVpqVO37XxrQYkzMoSo?size=800x600&size_mode=2

这是在我的logcat中找到的,我目前正在处理从url加载图片。

活动

        package com.downloader.newlevel.krim.newleveldownloader;

        import android.content.Intent;
        import android.graphics.Bitmap;
        import android.graphics.BitmapFactory;
        import android.os.AsyncTask;
        import android.os.Bundle;
        import android.support.v7.app.ActionBarActivity;
        import android.util.Log;
        import android.view.Menu;
        import android.view.MenuItem;
        import android.widget.ImageView;

        import java.io.InputStream;


        public class activity00 extends ActionBarActivity {

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity00);
                String url000 = "https://photos-4.dropbox.com/t/2/AAAxrzwz2B32dmtjRTNlT1vhQfVd5JuglMkbVV_m8BRkLg/12/145533347/png/32x32/1/_/1/2/Hourglass%20Addon%20by%20Redstone.png/CKPTskUgASACIAMgBCAFIAYgBygBKAI/Jpa4t4f3nMDieOULhjrmus_8mVpqVO37XxrQYkzMoSo?size=800x600&size_mode=2";
                new DownloadImageTask((ImageView) findViewById(R.id.image_main00)).execute(url000);
    Intent splash = new Intent(this, splash_activity.class);
    startActivity(splash);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.settings, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_search) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
}

AsyncTask下载图像

class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    ImageView bmImage;

    public DownloadImageTask(ImageView bmImage) {
        this.bmImage = bmImage;
    }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return mIcon11;
    }

    protected void onPostExecute(Bitmap result) {
        bmImage.setImageBitmap(result);
    }
 }

布局

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollView"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:cardview="http://schemas.android.com/apk/res-auto"
    tools:context=".activity00"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:orientation="horizontal">

        <TableLayout
            android:id="@+id/tableLayout_main00"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:stretchColumns="*">
            <TableRow>
                <Button
                    android:text="Script"
                    android:textAllCaps="false"
                    android:background="#ffffff"/>
                <Button
                    android:text="Add-on"
                    android:textAllCaps="false"
                    android:background="#fffffa6a"/>
            </TableRow> <TableRow>
            <Button
                android:text="Map"
                android:textAllCaps="false"
                android:background="#ff6ec0ff"/>
            <Button
                android:text="Skin"
                android:textAllCaps="false"
                android:background="#ffff6d66"/>
        </TableRow> <TableRow>
            <Button
                android:text="Texture Pack"
                android:textAllCaps="false"/>
            <Button
                android:text="Coming Soon"
                android:textAllCaps="false"/>
        </TableRow>
        </TableLayout>

        <TextView
            android:id="@+id/text_main00"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="New"
            android:textSize="20sp"
            android:layout_below="@+id/tableLayout_main00"
            android:clickable="true"
            android:gravity="right"
            android:layout_marginTop="20dp"/>

        <android.support.v7.widget.CardView
            android:id="@+id/cardview_main00"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            cardview:cardCornerRadius="4dp"
            android:layout_below="@+id/text_main00"
            android:clickable="true"
            android:layout_marginTop="5dp">

            <ImageView
                android:id="@+id/image_main00"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:scaleType="fitStart"/>

            <TextView
                android:id="@+id/text_main_cardview00"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Hourglass Addon by Redstone"
                android:layout_gravity="bottom"/>

        </android.support.v7.widget.CardView>

        <TextView
            android:id="@+id/text_main01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Popular"
            android:textSize="20sp"
            android:layout_below="@+id/cardview_main00"
            android:clickable="true"
            android:gravity="right"
            android:layout_marginTop="10dp"/>

        <android.support.v7.widget.CardView
            android:layout_below="@+id/text_main01"
            android:id="@+id/cardview_main01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            cardview:cardCornerRadius="4dp"
            android:clickable="true"
            android:layout_marginTop="5dp">

            <ImageView
                android:id="@+id/image_main01"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:scaleType="fitStart"/>

            <TextView
                android:id="@+id/text_main_cardview01"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Armor Display by Chan"
                android:layout_gravity="bottom"/>

        </android.support.v7.widget.CardView>

        <TextView
            android:id="@+id/text_main02"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Coming Soon"
            android:textSize="20sp"
            android:layout_below="@+id/cardview_main01"
            android:clickable="true"
            android:gravity="right"
            android:layout_marginTop="10dp"/>

        <android.support.v7.widget.CardView
            android:layout_below="@+id/text_main02"
            android:id="@+id/cardview_main02"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            cardview:cardCornerRadius="4dp"
            android:clickable="true"
            android:layout_marginTop="5dp">

            <ImageView
                android:id="@+id/image_main02"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:scaleType="fitStart"/>

            <TextView
                android:id="@+id/text_main_cardview02"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="PortalPX by TM"
                android:layout_above="@+id/text_main_cardview22"/>

            <TextView
                android:id="@+id/text_main_cardview22"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Limited Edition: Cabon Version"
                android:layout_gravity="bottom"/>


        </android.support.v7.widget.CardView>


    </RelativeLayout>

</ScrollView>

我不知道为什么这个logcat出现了。有人可以解释和解决吗?

2 个答案:

答案 0 :(得分:4)

“ViewRootImpl#2 Surface无效。”在logcat中意味着布局出错了。我通过再次编写整个布局来修复我...以确保一切正常:) 启动画面与此错误无关

答案 1 :(得分:0)

我不完全相信您的ImageView属于将内容视图设置为其中的布局。

再次检查该布局是否正确,因为在执行findViewById时未首先使用setContentViewLayoutInflator夸大父布局视图时会发生此错误。