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

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"???????
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?