Как проверить, является ли ImageView нулевым? - PullRequest
0 голосов
/ 19 сентября 2019

Это мой код добавления данных для моего sqlite, все остальное работает хорошо, но когда я не выбрал изображение для отображения в ImageView, затем щелкните btnAddData, приложение вылетает, но когда я выбираю изображение, система успешно вставляет данные в SQL.Как вы думаете, что мне нужно добавить в своем IF ELSE ЗАЯВЛЕНИИ, чтобы сделать тост "Пожалуйста, выберите подпись"

     private void AddData() {
    btnAddData.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view)
        {



            String time_out = edittime_out.getText().toString();
            String time_ino = edittime_in.getText().toString();
            String time_cuo = edittime_cu.getText().toString();
            String time_bro = edittime_br.getText().toString();
            String time_mao = edittime_ma.getText().toString();
            String time_tec = edittimei_te.getText().toString();
            String time_sta = edittimei_st.getText().toString();
            String time_sre = edittimei_sr.getText().toString();
            String time_qou = edittimei_qt.getText().toString();
            String serial_out = jobserialout.getText().toString();
            String timein_jobno = timeinjob.getText().toString();
            String time_co = timecompany.getText().toString();
            String time_dates = timedates.getText().toString();
            String timei_legend = timeilegend.getSelectedItem().toString();
            String timei_department = timedept.getText().toString();     
            Bitmap bitmap = ((BitmapDrawable) imageViews.getDrawable()).getBitmap();




            if (TextUtils.isEmpty(time_out)) {
                Toast.makeText(FormTimeout.this, "Please enter Time Out ", 
 Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_ino)) {
                Toast.makeText(FormTimeout.this, "Please enter Time In ", 
 Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_cuo)) {
                Toast.makeText(FormTimeout.this, "Please enter Customer ", 
 Toast.LENGTH_LONG).show();
                return;
            }
            if (TextUtils.isEmpty(time_bro)) {
                Toast.makeText(FormTimeout.this, "Please enter Branch ", 
  Toast.LENGTH_LONG).show();
                return;
            }
            if (TextUtils.isEmpty(time_mao)) {
                Toast.makeText(FormTimeout.this, "Please enter Machine ", 
 Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_tec)) {
                Toast.makeText(FormTimeout.this, "Please enter  Technician ", 
 Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_sta)) {
                Toast.makeText(FormTimeout.this, "Please enter Status ", 
 Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_sre)) {
                Toast.makeText(FormTimeout.this, "Please enter  SR", 
 Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_qou)) {
                Toast.makeText(FormTimeout.this, "Please enter Qoutation ", 
 Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(serial_out)) {
                Toast.makeText(FormTimeout.this, "Please enter Serial ", 
 Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(timein_jobno)) {
                Toast.makeText(FormTimeout.this, "Please enter Time in ID ", 
 Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(timei_legend)) {
                Toast.makeText(FormTimeout.this, "Please select Remarks ", 
 Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(timei_department)) {
                Toast.makeText(FormTimeout.this, "Please select Department ", 
 Toast.LENGTH_LONG).show();
                return;
            }


            boolean isInserted = myDb.insertDataout( time_out, time_ino, 
 time_cuo, time_bro, time_mao, time_tec, time_sta, time_sre,time_qou, 
 serial_out, 
 timein_jobno, timei_legend, time_co,  time_dates, timei_department, 
 Utils.getBytes(bitmap));
            if (isInserted == true) {
                Toast.makeText(FormTimeout.this, "Time Out Successfully", 
 Toast.LENGTH_LONG).show();
                edittime_out.setText("");
                edittime_in.setText("");
                edittime_cu.setText("");
                edittime_br.setText("");
                edittime_ma.setText("");
                edittimei_te.setText("");
                edittimei_st.setText("");
                edittimei_sr.setText("");
                edittimei_qt.setText("");
                jobserialout.setText("");
                timeinjob.setText("");


                Intent intent = new Intent(FormTimeout.this, 
 Timeoutsms.class);
                startActivity(intent);

            } else
                Toast.makeText(FormTimeout.this, "Time Out Failed", 
Toast.LENGTH_LONG).show();
        }
    });
}

activity_form_timeout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FormTimeout"
android:background="@color/white">


   <ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true">


    <LinearLayout
        android:id="@+id/linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@drawable/trans_white_rectangle">


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Time Out Form"
            android:textColor="#ffff"
            android:textSize="40sp"
            android:textStyle="bold"
            android:layout_marginBottom="5sp"
            android:paddingStart="10dp"
            android:paddingEnd="10dp"
            android:paddingTop="15dp"
            android:background="@drawable/backhead"
            android:drawableRight="@drawable/seervice3"
            />


        <EditText
            android:id="@+id/editText_idin"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentTop="true"
            android:inputType="number"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:paddingRight="10dp"
            android:paddingLeft="20dp"
            android:background="@drawable/rounded_white"
            android:drawablePadding="5dp"
            android:layout_marginBottom="10dp"
            android:hint="Job No."
            android:textSize="19dp"


            />

        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:columnCount="2"
            android:rowCount="1">

        <Button
            android:id="@+id/button_view"
            android:layout_width="150dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="20dp"
            android:layout_below="@id/editText_idin"
            android:text="SELECT ID"
            android:background="@drawable/custom_button3"
            android:textColor="@color/white"
            />

        <Button
            android:id="@+id/button_viewAll"
            android:layout_width="150dp"
            android:layout_marginRight="20dp"
            android:layout_height="match_parent"
            android:layout_gravity="right"
            android:text="TIME IN LIST"
            android:background="@drawable/custom_button3"
            android:textColor="@color/white"/>

        </GridLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:layout_margin="10dp"
            android:background="@color/black" />

        <Button
            android:layout_marginTop="10dp"
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_below="@+id/textView1"
            android:layout_centerHorizontal="true"
            android:layout_gravity="center"
            android:text="Generate current date and time"
            android:drawableLeft="@drawable/clock4"
            android:drawableRight="@drawable/calendar"
            android:background="@drawable/custom_button3"
            android:textColor="@color/white"/>



        <TextView
            android:id="@+id/editText_timein"
            android:layout_marginTop="13dp"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:background="@drawable/rounded_white"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:drawableLeft="@drawable/timein"
            android:textSize="20sp"
            android:textColor="@color/red"
            android:drawablePadding="5dp"
            android:paddingLeft="10dp"
            android:hint="Time In"/>

        <TextView
            android:id="@+id/editText_timei_out"
            android:layout_marginTop="20dp"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:background="@drawable/rounded_white"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:drawableLeft="@drawable/out3"
            android:textSize="20sp"
            android:textColor="@color/red"
            android:drawablePadding="5dp"
            android:paddingLeft="10dp"
            android:hint="Time Out"
            />


        <TextView
            android:id="@+id/editText_timei_cu"
            android:layout_marginTop="20dp"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:hint="Customer"
            android:background="@drawable/rounded_white"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:textColor="@color/black"
            android:drawableLeft="@drawable/cust"
            android:textSize="20dp"
            android:drawablePadding="5dp"
            android:layout_marginBottom="10dp"
            android:paddingLeft="10dp" />

        <TextView
            android:id="@+id/editText_timei_br"
            android:layout_marginTop="13dp"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:hint="Branch"
            android:background="@drawable/rounded_white"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:drawableLeft="@drawable/branch"
            android:textColor="@color/black"
            android:textSize="20sp"
            android:drawablePadding="5dp"
            android:layout_marginBottom="10dp"
            android:paddingLeft="10dp" />

        <TextView
            android:id="@+id/editText_timei_ma"
            android:layout_marginTop="13dp"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:hint="Machine"
            android:background="@drawable/rounded_white"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:drawableLeft="@drawable/machine"
            android:textColor="@color/black"
            android:textSize="20sp"
            android:drawablePadding="5dp"
            android:layout_marginBottom="10dp"
            android:paddingLeft="10dp" />


        <EditText
            android:id="@+id/editText_timei_te"
            android:layout_marginTop="13dp"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:hint="Technician"
            android:background="@drawable/rounded_white"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:drawableLeft="@drawable/tech2"
            android:textSize="20sp"
            android:drawablePadding="5dp"
            android:layout_marginBottom="10dp"
            android:paddingLeft="10dp"
            android:textColorHint="@drawable/selector2"/>

        <EditText
            android:id="@+id/editText_timei_st"
            android:layout_marginTop="13dp"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:hint="Status"
            android:background="@drawable/rounded_white"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:drawableLeft="@drawable/status"
            android:textSize="20sp"
            android:drawablePadding="5dp"
            android:layout_marginBottom="10dp"
            android:paddingLeft="10dp"
            android:textColorHint="@drawable/selector2"/>

        <EditText
            android:id="@+id/editText_timei_sr"
            android:layout_marginTop="13dp"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:hint="SR No."
            android:background="@drawable/rounded_white"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:drawableLeft="@drawable/sr"
            android:textSize="20sp"
            android:drawablePadding="5dp"
            android:layout_marginBottom="10dp"
            android:paddingLeft="10dp"
            android:textColorHint="@drawable/selector2"/>

        <EditText
            android:id="@+id/editText_timei_qt"
            android:layout_marginTop="13dp"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:hint="Qoutation"
            android:background="@drawable/rounded_white"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:drawableLeft="@drawable/quote"
            android:textSize="20sp"
            android:drawablePadding="5dp"
            android:layout_marginBottom="10dp"
            android:paddingLeft="10dp"
            android:textColorHint="@drawable/selector2"/>


        <androidx.appcompat.widget.AppCompatSpinner
            android:id="@+id/legend"
            android:layout_gravity="center"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:background="@android:drawable/btn_dropdown"
            android:spinnerMode="dropdown"/>


        <ImageView
            android:layout_above="@+id/layout_button"
            android:id="@+id/image_view"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_gravity="center"
            android:layout_marginTop="30dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/trans_white_rectangle"/>


        <LinearLayout
            android:id="@+id/layout_button"
            android:layout_alignParentBottom="true"
            android:weightSum="2"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <Button
                android:id="@+id/signatures"
                android:text="SIGN"
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"/>

            <Button
                android:id="@+id/select_image"
                android:text="SELECT SIGNATURE"
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"/>

        </LinearLayout>


        <TextView
            android:id="@+id/textViewr"
            android:layout_marginTop="13dp"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@drawable/rounded_white"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:textSize="20sp"
            android:textColor="@color/red"
            android:drawablePadding="5dp"
            android:paddingLeft="10dp"
            android:hint="Serial"
            android:visibility="invisible"/>



        <TextView
            android:id="@+id/textViewJobIn"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@drawable/rounded_white"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:textSize="20sp"
            android:textColor="@color/red"
            android:drawablePadding="5dp"
            android:paddingLeft="10dp"
            android:visibility="invisible"/>

        <TextView
            android:id="@+id/editText_timei_co"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@drawable/rounded_white"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:textSize="20sp"
            android:textColor="@color/red"
            android:drawablePadding="5dp"
            android:paddingLeft="10dp"
            android:text="JCG Marketing Group Inc."
            android:visibility="invisible"/>

        <TextView
            android:id="@+id/editText_timei_timedate"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@drawable/rounded_white"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:textSize="20sp"
            android:textColor="@color/red"
            android:drawablePadding="5dp"
            android:paddingLeft="10dp"
            android:visibility="invisible"/>


        <TextView
            android:id="@+id/department"
            android:layout_marginTop="13dp"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@drawable/rounded_white"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:textSize="20sp"
            android:textColor="@color/red"
            android:text="Sevice Department"
            android:drawablePadding="5dp"
            android:paddingLeft="10dp"
            android:visibility="invisible"/>


        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:columnCount="1"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingBottom="20dp"
            android:rowCount="1">


            <Button
                android:id="@+id/button_addout"
                android:layout_width="250dp"
                android:layout_height="match_parent"
                android:layout_below="@+id/textView1"
                android:layout_centerHorizontal="true"
                android:layout_gravity="center"
                android:gravity="center"
                android:background="@drawable/custom_button3"
                android:text="SAVE"
                android:textColor="#ffffff"
                android:drawableLeft="@drawable/save"
                android:paddingLeft="20dp"/>



        </GridLayout>


    </LinearLayout>


</ScrollView>


</RelativeLayout>

Databasehelper code для добавления данных.

  public boolean insertDataout(String timei_out, String timei_in, String 
timei_cu, String timei_br, String timei_ma, String timei_te, String timei_st, 
String timei_sr, String timei_qt, String serial_out, String timein_jobno, 
String 
timei_legend, String timei_company, String timei_date, String timei_dept, 
byte[] 
 signature) throws SQLiteException {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(COL_2b, timei_out);
    contentValues.put(COL_3b, timei_in);
    contentValues.put(COL_4b, timei_cu);
    contentValues.put(COL_5b, timei_br);
    contentValues.put(COL_6b, timei_ma);
    contentValues.put(COL_7b, timei_te);
    contentValues.put(COL_8b, timei_st);
    contentValues.put(COL_9b, timei_sr);
    contentValues.put(COL_10b, timei_qt);
    contentValues.put(COL_11b, serial_out);
    contentValues.put(COL_12b, timein_jobno);
    contentValues.put(COL_13b, timei_legend);
    contentValues.put(COL_14b, timei_company);
    contentValues.put(COL_15b, timei_date);
    contentValues.put(COL_16b, timei_dept);
    contentValues.put(COL_17b, signature);

    long result = db.insert(TABLE_NAME_OUT , null, contentValues);

    if (result == -1)
        return false;
    else
        return true;
}

Это ошибка в Logcat. ОШИБКА LOGCAT

 java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Bitmap 
 android.graphics.drawable.BitmapDrawable.getBitmap()' on a null object reference

Ответы [ 3 ]

0 голосов
/ 19 сентября 2019

Вы не включили это свойство для imageView, чтобы получить его отрисовку.

imageView.buildDrawingCache();

, затем получите bitmap из него.

final Bitmap bitmap = ((BitmapDrawable) imageViews.getDrawable ()). GetBitmap ();

if (bitmap == null) {

// показать тост здесь

}

Решение 2: -

объявить эту переменную глобально

Uri pickedImage;

и при нажатии кнопки btnAddData.setOnClickListener

добавить это условие

if(pickedImage==null ){
// condition where image is not selected
}

Как это

btnAddData.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            imageViews = (ImageView) findViewById(R.id.image_view);


            String time_out = edittime_out.getText().toString();
            String time_ino = edittime_in.getText().toString();
            String time_cuo = edittime_cu.getText().toString();
            String time_bro = edittime_br.getText().toString();
            String time_mao = edittime_ma.getText().toString();
            String time_tec = edittimei_te.getText().toString();
            String time_sta = edittimei_st.getText().toString();
            String time_sre = edittimei_sr.getText().toString();
            String time_qou = edittimei_qt.getText().toString();
            String serial_out = jobserialout.getText().toString();
            String timein_jobno = timeinjob.getText().toString();
            String time_co = timecompany.getText().toString();
            String time_dates = timedates.getText().toString();
            String timei_legend = timeilegend.getSelectedItem().toString();
            String timei_department = timedept.getText().toString();



            if (TextUtils.isEmpty(time_out)) {
                Toast.makeText(FormTimeout.this, "Please enter Time Out ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_ino)) {
                Toast.makeText(FormTimeout.this, "Please enter Time In ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_cuo)) {
                Toast.makeText(FormTimeout.this, "Please enter Customer ", Toast.LENGTH_LONG).show();
                return;
            }
            if (TextUtils.isEmpty(time_bro)) {
                Toast.makeText(FormTimeout.this, "Please enter Branch ", Toast.LENGTH_LONG).show();
                return;
            }
            if (TextUtils.isEmpty(time_mao)) {
                Toast.makeText(FormTimeout.this, "Please enter Machine ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_tec)) {
                Toast.makeText(FormTimeout.this, "Please enter  Technician ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_sta)) {
                Toast.makeText(FormTimeout.this, "Please enter Status ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_sre)) {
                Toast.makeText(FormTimeout.this, "Please enter  SR", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_qou)) {
                Toast.makeText(FormTimeout.this, "Please enter Qoutation ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(serial_out)) {
                Toast.makeText(FormTimeout.this, "Please enter Serial ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(timein_jobno)) {
                Toast.makeText(FormTimeout.this, "Please enter Time in ID ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(timei_legend)) {
                Toast.makeText(FormTimeout.this, "Please select Remarks ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(timei_department)) {
                Toast.makeText(FormTimeout.this, "Please select Department ", Toast.LENGTH_LONG).show();
                return;
            }


           if(pickedImage==null ){
// condition where image is not selected
Toast.makeText(FormTimeout.this, "Please select Signature ", Toast.LENGTH_LONG).show();
return
}
final Bitmap bitmap = ((BitmapDrawable) imageViews.getDrawable()).getBitmap();




        boolean isInserted = myDb.insertDataout( time_out, time_ino, time_cuo, time_bro, time_mao, time_tec, time_sta, time_sre,time_qou, serial_out, timein_jobno, timei_legend, time_co,  time_dates, timei_department, Utils.getBytes(bitmap));
            if (isInserted == true) {
                Toast.makeText(FormTimeout.this, "Time Out Successfully", Toast.LENGTH_LONG).show();
                edittime_out.setText("");
                edittime_in.setText("");
                edittime_cu.setText("");
                edittime_br.setText("");
                edittime_ma.setText("");
                edittimei_te.setText("");
                edittimei_st.setText("");
                edittimei_sr.setText("");
                edittimei_qt.setText("");
                jobserialout.setText("");
                timeinjob.setText("");


                Intent intent = new Intent(FormTimeout.this, Timeoutsms.class);
                startActivity(intent);

            } else
                Toast.makeText(FormTimeout.this, "Time Out Failed", Toast.LENGTH_LONG).show();
        }
    });
0 голосов
/ 20 сентября 2019

ImageView пытается кешировать предыдущие Uri.Вам необходимо эффективно сбросить его до loading a new Uri`, как показано ниже.

// in your onActivityResult()
imageViews.setImageURI(null);
imageViews.setImageURI(pickedImage);

И вам необходимо initialize ваш imageViews в onCreate()

// write this line in your onCreate()
imageViews = (ImageView) findViewById(R.id.image_view);

И удалить над строкой из AddData () , как показано ниже.

private void AddData() {
    btnAddData.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            // remove below line and add it to onCreate()
            imageViews = (ImageView) findViewById(R.id.image_view);

            // your other codes here
            ............

Обновление: Измените свой AddData() метод следующим образом.

private void AddData() {

    btnAddData.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String time_out = edittime_out.getText().toString();
            String time_ino = edittime_in.getText().toString();
            String time_cuo = edittime_cu.getText().toString();
            String time_bro = edittime_br.getText().toString();
            String time_mao = edittime_ma.getText().toString();
            String time_tec = edittimei_te.getText().toString();
            String time_sta = edittimei_st.getText().toString();
            String time_sre = edittimei_sr.getText().toString();
            String time_qou = edittimei_qt.getText().toString();
            String serial_out = jobserialout.getText().toString();
            String timein_jobno = timeinjob.getText().toString();
            String time_co = timecompany.getText().toString();
            String time_dates = timedates.getText().toString();
            String timei_legend = timeilegend.getSelectedItem().toString();
            String timei_department = timedept.getText().toString();


            if (TextUtils.isEmpty(time_out)) {
                Toast.makeText(FormTimeout.this, "Please enter Time Out ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_ino)) {
                Toast.makeText(FormTimeout.this, "Please enter Time In ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_cuo)) {
                Toast.makeText(FormTimeout.this, "Please enter Customer ", Toast.LENGTH_LONG).show();
                return;
            }
            if (TextUtils.isEmpty(time_bro)) {
                Toast.makeText(FormTimeout.this, "Please enter Branch ", Toast.LENGTH_LONG).show();
                return;
            }
            if (TextUtils.isEmpty(time_mao)) {
                Toast.makeText(FormTimeout.this, "Please enter Machine ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_tec)) {
                Toast.makeText(FormTimeout.this, "Please enter  Technician ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_sta)) {
                Toast.makeText(FormTimeout.this, "Please enter Status ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_sre)) {
                Toast.makeText(FormTimeout.this, "Please enter  SR", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(time_qou)) {
                Toast.makeText(FormTimeout.this, "Please enter Qoutation ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(serial_out)) {
                Toast.makeText(FormTimeout.this, "Please enter Serial ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(timein_jobno)) {
                Toast.makeText(FormTimeout.this, "Please enter Time in ID ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(timei_legend)) {
                Toast.makeText(FormTimeout.this, "Please select Remarks ", Toast.LENGTH_LONG).show();
                return;
            }

            if (TextUtils.isEmpty(timei_department)) {
                Toast.makeText(FormTimeout.this, "Please select Department ", Toast.LENGTH_LONG).show();
                return;
            }


            if  (imageViews != null && imageViews.getDrawable() == null){
                Toast.makeText(FormTimeout.this, "Please select Signature ", Toast.LENGTH_LONG).show();
                return;
             }



        final Bitmap bitmap = ((BitmapDrawable) imageViews.getDrawable()).getBitmap();

        boolean isInserted = myDb.insertDataout( time_out, time_ino, time_cuo, time_bro, time_mao, time_tec, time_sta, time_sre,time_qou, serial_out, timein_jobno, timei_legend, time_co,  time_dates, timei_department, Utils.getBytes(bitmap));
            if (isInserted == true) {
                Toast.makeText(FormTimeout.this, "Time Out Successfully", Toast.LENGTH_LONG).show();
                edittime_out.setText("");
                edittime_in.setText("");
                edittime_cu.setText("");
                edittime_br.setText("");
                edittime_ma.setText("");
                edittimei_te.setText("");
                edittimei_st.setText("");
                edittimei_sr.setText("");
                edittimei_qt.setText("");
                jobserialout.setText("");
                timeinjob.setText("");


                Intent intent = new Intent(FormTimeout.this, Timeoutsms.class);
                startActivity(intent);

            } else
                Toast.makeText(FormTimeout.this, "Time Out Failed", Toast.LENGTH_LONG).show();
        }
    });
}

Надеюсь, он вам поможет.

0 голосов
/ 19 сентября 2019

Первое изменение

if (imageViews != null) {
    final Bitmap bitmap = ((BitmapDrawable) imageViews.getDrawable()).getBitmap();  
}

Также изменение,

if  (imageViews != null && imageViews.getDrawable() == null){
    Toast.makeText(FormTimeout.this, "Please select Signature ", Toast.LENGTH_LONG).show();
    return;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...