PlayInSea 2019-04-15 01:29 采纳率: 0%
浏览 347
已结题

ImageView 返回为空!!!!

这是我的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"


    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp">

        <LinearLayout
            android:id="@+id/line111"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/book_image_edit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/book1_pic" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1.8"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="40dp">

                <TextView

                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center_vertical"
                    android:text="标题:" />

                <EditText
                    android:id="@+id/book_name_edit"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="1dp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="40dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center_vertical"
                    android:text="作者:" />

                <EditText
                    android:id="@+id/book_author_edit"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="1dp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="40dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center_vertical"
                    android:text="出版社:" />

                <EditText
                    android:id="@+id/book_press_edit"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="1dp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="40dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center_vertical"
                    android:text="出版时间:" />

                <EditText
                    android:id="@+id/book_presstime_edit"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="1dp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="40dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center_vertical"
                    android:text="ISBN:" />

                <EditText
                    android:id="@+id/book_isbn_edit"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="1dp" />
            </LinearLayout>


        </LinearLayout>
    </LinearLayout>

 //初始化控件   onCreate(){   //在onCreate()内
                        setContentview(上面那个布局文件);   //略写

        ImageView book_pic_edit=(ImageView)findViewById(R.id.book_image_edit);
        EditText book_name=(EditText) findViewById(R.id.book_name_edit);
        EditText author=(EditText)findViewById(R.id.book_author_edit);
        EditText press=(EditText) findViewById(R.id.book_press_edit);
        EditText press_time=(EditText)findViewById(R.id.book_presstime_edit);
        EditText isbn=(EditText) findViewById(R.id.book_isbn_edit);
        Spinner reading_state=(Spinner) findViewById(R.id.spinner_readingstate);
        Spinner bookshelf=(Spinner) findViewById(R.id.spinner_bookshelf_edit);
        EditText book_source=(EditText) findViewById(R.id.book_source_edit);
                }

这里一个问题就是, ImageView book_pic_edit=(ImageView)findViewById(R.id.book_image_edit); book_pic_edit为null??? 为什么会这样 其他的都有值
图片说明

请大神搭救!!!

  • 写回答

9条回答 默认 最新

  • chenghanjiang 2019-04-15 10:50
    关注

    android:id="@+id/line111"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1">

                    :layout_width="0dp"???????
    
    评论

报告相同问题?