问:
Image upload issue with Codeigniter
I'm stuck with an issue updating images. I've created image upload which works fine but when I try to update an entry with other details which already has an image, it throws an error. Is there a way we can skip the image upload check altogether and the entry updates with or without the image?

View:

        <?php require_once("header.php"); ?>

        <?php require_once("sidebar.php"); ?>

Add Mick Chocolate

                      Chocolate
                      / Home / Add Mick Chocolate

Input

                    <?php

                        echo form_open_multipart('Admin/admin_add_image');

                    ?>

                      <form class="form-horizontal" action = "" method ="post">

                          Name

                            <input type="text" id="text1" name="chocolate_name" pattern="^[A-Za-z -]+$" required >

                          Price

                            <input type="text" id="text2" name="chocolate_price" pattern="^(0|[1-9][0-9]*)$" required >

                          Upload Image

                            <input type="file" id="text3" name="file_to_upload" accept="image/gif, image/jpeg, image/png, image/jpg">

                                <button type="submit" name="btn_add" class="btn btn-info">Add</button>
                      </form>

               <?php require_once("footer.php"); ?>

**Model**

```php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class AdminModel extends CI_Model {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function admin_register_done()
    {
        $admin_name=$this->input->post('admin_name');
        $admin_email=$this->input->post('admin_email');
        $admin_mobileno=$this->input->post('admin_mobileno');
        $admin_username=$this->input->post('admin_username');
        $admin_password=$this->input->post('admin_password');
        $data=array(
            'admin_name'=>$admin_name,
            'admin_email'=>$admin_email,
            'admin_mobileno'=>$admin_mobileno,
            'admin_username'=>$admin_username,
            'admin_password'=>$admin_password
        );
        $this->db->insert('tbl_admin_registration',$data);
    }
    public function admin_login_done()
    {
        $admin_username=$this->input->post('admin_username');
        $admin_password=$this->input->post('admin_password');
        $this->db->select('admin_username','admin_password');
        $this->db->from('tbl_admin_registration');
        $this->db->where('admin_username',$admin_username);
        $this->db->where("admin_password",$admin_password);
        return $query=$this->db->get();
    }
    public function admin_add_image_done($image)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>'http://candymart.co.in/Admin/uploads/'.$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_chocolate',$data);
    }
        public function admin_add_image_done1()
    {

        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_chocolate',$data);
    }
    public function admin_add_madhurimage_done()
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_madhurchocolate',$data);
    }
    public function admin_add_crystalimage_done()
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_crystalchocolate',$data);
    }
    public function admin_add_candyimage_done()
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_candychocolate',$data);
    }

        public function admin_display_image_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_chocolate');
        $query=$this->db->get();
        return $query->result();
    }
        public function admin_display_madhurimage_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_madhurchocolate');
        $query=$this->db->get();
        return $query->result();
    }
        public function admin_display_crystalimage_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_crystalchocolate');
        $query=$this->db->get();
        return $query->result();
    }
       public function admin_display_candyimage_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_candychocolate');
        $query=$this->db->get();
        return $query->result();
    }
    public function admin_delete_image_done($id)
    {
        $this->db->where('tbl_admin_chocolate.id',$id);
        return $this->db->delete('tbl_admin_chocolate');

    }
    public function admin_delete_madhurimage_done($id)
    {
        $this->db->where('tbl_admin_madhurchocolate.id',$id);
        return $this->db->delete('tbl_admin_madhurchocolate');

    }
    public function admin_delete_crystalimage_done($id)
    {
        $this->db->where('tbl_admin_crystalchocolate.id',$id);
        return $this->db->delete('tbl_admin_crystalchocolate');

    }
        public function admin_delete_candyimage_done($id)
    {
        $this->db->where('tbl_admin_candychocolate.id',$id);
        return $this->db->delete('tbl_admin_candychocolate');

    }
    public function admin_edit_chocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_chocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_edit_madhurchocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_madhurchocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_edit_crystalchocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_crystalchocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_edit_candychocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_candychocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_update_chocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>'http://candymart.co.in/Admin/uploads/'.$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_chocolate.id',$id);
        return $this->db->update('tbl_admin_chocolate',$data);
    }
        public function admin_update_madhurchocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_madhurchocolate.id',$id);
        return $this->db->update('tbl_admin_madhurchocolate',$data);
    }
        public function admin_update_crystalchocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_crystalchocolate.id',$id);
        return $this->db->update('tbl_admin_crystalchocolate',$data);
    }
        public function admin_update_candychocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_candychocolate.id',$id);
        return $this->db->update('tbl_admin_candychocolate',$data);
    }
}
</code>```

Controller

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Admin extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
        $this->load->view('manisha_admin');
    }
    public function admin_register()
    {
        $this->load->view('admin_register');
    }
    public function admin_register_data()
    {

        $this->load->model('AdminModel');
        $this->AdminModel->admin_register_done();
        $this->load->view('admin_login');
    }
    public function admin_login()
    {
        $this->load->view('admin_login');
    }
    public function admin_login_data()
    {

        $this->load->model('AdminModel');
        $this->AdminModel->admin_login_done();
        $data['sub'] = $this->AdminModel->admin_display_image_done();
        $this->load->view('add_image',$data);
    }
    public function admin_add_image()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            //$image = 'http://candymart.co.in/Admin/uploads/1.JPG';
            $this->load->view('add_image');
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            //$image = $_FILES['file_to_upload']['name'];
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_image_done();

         }
    }
    public function admin_add_madhurimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('add_madhurimage', $error);
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_madhurimage_done();
         }
    }
        public function admin_add_crystalimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('add_crystalimage', $error);
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_crystalimage_done();
         }
    }
        public function admin_add_candyimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('add_candyimage', $error);
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_candyimage_done();
         }
    }
    public function admin_edit_image()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_chocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id1');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_chocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_image_done();
            $this->load->view('display_image',$data);
         }
    }
    public function admin_edit_madhurimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_madhurchocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id2');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_madhurchocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_madhurimage_done();
            $this->load->view('display_madhurimage',$data);
         }
    }
    public function admin_edit_crystalimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_crystalchocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id3');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_crystalchocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_crystalimage_done();
            $this->load->view('display_crystalimage',$data);

         }
    }
    public function admin_edit_candyimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_candychocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id4');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_candychocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_candyimage_done();
            $this->load->view('display_candyimage',$data);
         }
    }
    public function admin_display_image()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_image_done();
        $this->load->view('display_image',$data);
    }
    public function admin_display_madhurimage()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_madhurimage_done();
        $this->load->view('display_madhurimage',$data);
    }
    public function admin_display_crystalimage()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_crystalimage_done();
        $this->load->view('display_crystalimage',$data);
    }
    public function admin_display_candyimage()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_candyimage_done();
        $this->load->view('display_candyimage',$data);
    }

    public function admin_delete_image()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_image_done($id);
        $data['sub'] = $this->AdminModel->admin_display_image_done();
        $this->load->view('display_image',$data);
    }
        public function admin_delete_madhurimage()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_madhurimage_done($id);
        $data['sub'] = $this->AdminModel->admin_display_madhurimage_done();
        $this->load->view('display_madhurimage',$data);

    }
            public function admin_delete_crystalimage()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_crystalimage_done($id);
        $data['sub'] = $this->AdminModel->admin_display_crystalimage_done();
        $this->load->view('display_crystalimage',$data);

    }
            public function admin_delete_candyimage()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_candyimage_done($id);
        $data['sub'] = $this->AdminModel->admin_display_candyimage_done();
        $this->load->view('display_candyimage',$data);
    }
    public function admin_edit_chocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user1']=$this->AdminModel->admin_edit_chocolate_done($id);
        $this->load->view('edit_chocolate',$data);

    }
        public function admin_edit_madhurchocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user2']=$this->AdminModel->admin_edit_madhurchocolate_done($id);
        $this->load->view('edit_madhurchocolate',$data);

    }
        public function admin_edit_crystalchocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user3']=$this->AdminModel->admin_edit_crystalchocolate_done($id);
        $this->load->view('edit_crystalchocolate',$data);

    }
        public function admin_edit_candychocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user4']=$this->AdminModel->admin_edit_candychocolate_done($id);
        $this->load->view('edit_candychocolate',$data);

    }
        public function admin_update_chocolate()
    {
        $id = $this->input->post('hidden_id1');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_chocolate_done($id);
    }
        public function admin_update_madhurchocolate()
    {
        $id = $this->input->post('hidden_id2');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_madhurchocolate_done($id);

    }
        public function admin_update_crystalchocolate()
    {
        $id = $this->input->post('hidden_id3');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_crystalchocolate_done($id);

    }
        public function admin_update_candychocolate()
    {
        $id = $this->input->post('hidden_id4');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_candychocolate_done($id);

    }
        public function admin_logout()
    {
        $user_data = $this->session->all_userdata();
        foreach ($user_data as $key => $value) {
            if ($key != 'session_id' && $key != 'ip_address' && $key != 'user_agent' && $key != 'last_activity') {
                $this->session->unset_userdata($key);
            }
        }
        $this->session->sess_destroy();
        redirect('Admin/index');
     }

}
```

答:
I have noticed you have write form tag 2 time. check the view

```<code><?php
echo form_open_multipart('Admin/admin_add_image');
?>
<form class="form-horizontal" action = "" method ="post">
</code>```

First remove one of them and try to upload image again.

Title: Image upload issue with Codeigniter

Body:
I'm stuck with an issue updating images. I've created image upload which works fine but when I try to update an entry with other details which already has an image, it throws an error. Is there a way we can skip the image upload check altogether and the entry updates with or without the image?

View:

        <?php require_once("header.php"); ?>

        <?php require_once("sidebar.php"); ?>

Add Mick Chocolate

                      Chocolate
                      / Home / Add Mick Chocolate

Input

                    <?php

                        echo form_open_multipart('Admin/admin_add_image');

                    ?>

                      <form class="form-horizontal" action = "" method ="post">

                          Name

                            <input type="text" id="text1" name="chocolate_name" pattern="^[A-Za-z -]+$" required >

                          Price

                            <input type="text" id="text2" name="chocolate_price" pattern="^(0|[1-9][0-9]*)$" required >

                          Upload Image

                            <input type="file" id="text3" name="file_to_upload" accept="image/gif, image/jpeg, image/png, image/jpg">

                                <button type="submit" name="btn_add" class="btn btn-info">Add</button>
                      </form>

               <?php require_once("footer.php"); ?>

**Model**

```php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class AdminModel extends CI_Model {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function admin_register_done()
    {
        $admin_name=$this->input->post('admin_name');
        $admin_email=$this->input->post('admin_email');
        $admin_mobileno=$this->input->post('admin_mobileno');
        $admin_username=$this->input->post('admin_username');
        $admin_password=$this->input->post('admin_password');
        $data=array(
            'admin_name'=>$admin_name,
            'admin_email'=>$admin_email,
            'admin_mobileno'=>$admin_mobileno,
            'admin_username'=>$admin_username,
            'admin_password'=>$admin_password
        );
        $this->db->insert('tbl_admin_registration',$data);
    }
    public function admin_login_done()
    {
        $admin_username=$this->input->post('admin_username');
        $admin_password=$this->input->post('admin_password');
        $this->db->select('admin_username','admin_password');
        $this->db->from('tbl_admin_registration');
        $this->db->where('admin_username',$admin_username);
        $this->db->where("admin_password",$admin_password);
        return $query=$this->db->get();
    }
    public function admin_add_image_done($image)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>'http://candymart.co.in/Admin/uploads/'.$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_chocolate',$data);
    }
        public function admin_add_image_done1()
    {

        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_chocolate',$data);
    }
    public function admin_add_madhurimage_done()
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_madhurchocolate',$data);
    }
    public function admin_add_crystalimage_done()
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_crystalchocolate',$data);
    }
    public function admin_add_candyimage_done()
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_candychocolate',$data);
    }

        public function admin_display_image_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_chocolate');
        $query=$this->db->get();
        return $query->result();
    }
        public function admin_display_madhurimage_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_madhurchocolate');
        $query=$this->db->get();
        return $query->result();
    }
        public function admin_display_crystalimage_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_crystalchocolate');
        $query=$this->db->get();
        return $query->result();
    }
       public function admin_display_candyimage_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_candychocolate');
        $query=$this->db->get();
        return $query->result();
    }
    public function admin_delete_image_done($id)
    {
        $this->db->where('tbl_admin_chocolate.id',$id);
        return $this->db->delete('tbl_admin_chocolate');

    }
    public function admin_delete_madhurimage_done($id)
    {
        $this->db->where('tbl_admin_madhurchocolate.id',$id);
        return $this->db->delete('tbl_admin_madhurchocolate');

    }
    public function admin_delete_crystalimage_done($id)
    {
        $this->db->where('tbl_admin_crystalchocolate.id',$id);
        return $this->db->delete('tbl_admin_crystalchocolate');

    }
        public function admin_delete_candyimage_done($id)
    {
        $this->db->where('tbl_admin_candychocolate.id',$id);
        return $this->db->delete('tbl_admin_candychocolate');

    }
    public function admin_edit_chocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_chocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_edit_madhurchocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_madhurchocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_edit_crystalchocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_crystalchocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_edit_candychocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_candychocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_update_chocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>'http://candymart.co.in/Admin/uploads/'.$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_chocolate.id',$id);
        return $this->db->update('tbl_admin_chocolate',$data);
    }
        public function admin_update_madhurchocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_madhurchocolate.id',$id);
        return $this->db->update('tbl_admin_madhurchocolate',$data);
    }
        public function admin_update_crystalchocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_crystalchocolate.id',$id);
        return $this->db->update('tbl_admin_crystalchocolate',$data);
    }
        public function admin_update_candychocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_candychocolate.id',$id);
        return $this->db->update('tbl_admin_candychocolate',$data);
    }
}

Controller

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Admin extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
        $this->load->view('manisha_admin');
    }
    public function admin_register()
    {
        $this->load->view('admin_register');
    }
    public function admin_register_data()
    {

        $this->load->model('AdminModel');
        $this->AdminModel->admin_register_done();
        $this->load->view('admin_login');
    }
    public function admin_login()
    {
        $this->load->view('admin_login');
    }
    public function admin_login_data()
    {

        $this->load->model('AdminModel');
        $this->AdminModel->admin_login_done();
        $data['sub'] = $this->AdminModel->admin_display_image_done();
        $this->load->view('add_image',$data);
    }
    public function admin_add_image()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            //$image = 'http://candymart.co.in/Admin/uploads/1.JPG';
            $this->load->view('add_image');
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            //$image = $_FILES['file_to_upload']['name'];
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_image_done();

         }
    }
    public function admin_add_madhurimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('add_madhurimage', $error);
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_madhurimage_done();
         }
    }
        public function admin_add_crystalimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('add_crystalimage', $error);
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_crystalimage_done();
         }
    }
        public function admin_add_candyimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('add_candyimage', $error);
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_candyimage_done();
         }
    }
    public function admin_edit_image()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_chocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id1');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_chocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_image_done();
            $this->load->view('display_image',$data);
         }
    }
    public function admin_edit_madhurimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_madhurchocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id2');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_madhurchocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_madhurimage_done();
            $this->load->view('display_madhurimage',$data);
         }
    }
    public function admin_edit_crystalimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_crystalchocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id3');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_crystalchocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_crystalimage_done();
            $this->load->view('display_crystalimage',$data);

         }
    }
    public function admin_edit_candyimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_candychocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id4');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_candychocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_candyimage_done();
            $this->load->view('display_candyimage',$data);
         }
    }
    public function admin_display_image()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_image_done();
        $this->load->view('display_image',$data);
    }
    public function admin_display_madhurimage()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_madhurimage_done();
        $this->load->view('display_madhurimage',$data);
    }
    public function admin_display_crystalimage()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_crystalimage_done();
        $this->load->view('display_crystalimage',$data);
    }
    public function admin_display_candyimage()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_candyimage_done();
        $this->load->view('display_candyimage',$data);
    }

    public function admin_delete_image()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_image_done($id);
        $data['sub'] = $this->AdminModel->admin_display_image_done();
        $this->load->view('display_image',$data);
    }
        public function admin_delete_madhurimage()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_madhurimage_done($id);
        $data['sub'] = $this->AdminModel->admin_display_madhurimage_done();
        $this->load->view('display_madhurimage',$data);

    }
            public function admin_delete_crystalimage()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_crystalimage_done($id);
        $data['sub'] = $this->AdminModel->admin_display_crystalimage_done();
        $this->load->view('display_crystalimage',$data);

    }
            public function admin_delete_candyimage()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_candyimage_done($id);
        $data['sub'] = $this->AdminModel->admin_display_candyimage_done();
        $this->load->view('display_candyimage',$data);
    }
    public function admin_edit_chocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user1']=$this->AdminModel->admin_edit_chocolate_done($id);
        $this->load->view('edit_chocolate',$data);

    }
        public function admin_edit_madhurchocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user2']=$this->AdminModel->admin_edit_madhurchocolate_done($id);
        $this->load->view('edit_madhurchocolate',$data);

    }
        public function admin_edit_crystalchocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user3']=$this->AdminModel->admin_edit_crystalchocolate_done($id);
        $this->load->view('edit_crystalchocolate',$data);

    }
        public function admin_edit_candychocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user4']=$this->AdminModel->admin_edit_candychocolate_done($id);
        $this->load->view('edit_candychocolate',$data);

    }
        public function admin_update_chocolate()
    {
        $id = $this->input->post('hidden_id1');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_chocolate_done($id);
    }
        public function admin_update_madhurchocolate()
    {
        $id = $this->input->post('hidden_id2');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_madhurchocolate_done($id);

    }
        public function admin_update_crystalchocolate()
    {
        $id = $this->input->post('hidden_id3');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_crystalchocolate_done($id);

    }
        public function admin_update_candychocolate()
    {
        $id = $this->input->post('hidden_id4');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_candychocolate_done($id);

    }
        public function admin_logout()
    {
        $user_data = $this->session->all_userdata();
        foreach ($user_data as $key => $value) {
            if ($key != 'session_id' && $key != 'ip_address' && $key != 'user_agent' && $key != 'last_activity') {
                $this->session->unset_userdata($key);
            }
        }
        $this->session->sess_destroy();
        redirect('Admin/index');
     }

}

Body:
I have noticed you have write form tag 2 time. check the view

<?php
echo form_open_multipart('Admin/admin_add_image');
?>
<form class="form-horizontal" action = "" method ="post">

First remove one of them and try to upload image again.


来源: stackexchange

问:
how to log SOAP request/response using log4j2 in separate log files dynamically
Need to write separate log files based on an apikey using log4j2 for SOAP request and response. we are client side or consuming SOAP webservice.

I am able to write separate log files based on an apikey for REST request & response but not sure how to do for SOAP request & response

code to write logs in separate log files is as follows

Need to write separate log files based on an apikey using log4j2 for SOAP request and response. we are client side or consuming SOAP webservice.

I am able to write separate log files based on an apikey for REST request & response but not sure how to do for SOAP request & response

code to write logs in separate log files is as follows :

```<code>public final class SPRestLog4j2Logger extends org.apache.logging.log4j.core.async.AsyncLogger {

    private SPRestLog4j2Logger(LoggerContext context, String name, MessageFactory msgFactory) {
        super(context, name, msgFactory);
        this.setLevel(Level.ALL);
    }

    public static SPRestLog4j2Logger configureCategoryLogger(String apiKey, String loggingPath) {
        LoggerContext context = new AsyncLoggerContext(apiKey);
        MessageFactory msgFactory = new FormattedMessageFactory();
        SPRestLog4j2Logger logger = new SPRestLog4j2Logger(context, apiKey, msgFactory);

        RandomAccessFileAppender appender = RandomAccessFileAppender
            .createAppender(
                loggingPath + apiKey + ".log", // filename
                "true", // append
                "file_appender-" + apiKey, // name
                "true", // immediateFlush
                "", // bufferSize
                "true", // ignoreExceptions
                PatternLayout.createLayout(
                    "%-5p - [%d] - [%t] - [%l]  : %m%n", null,
                    null, Charset.forName("UTF-8"), true, true, apiKey, apiKey), null, // filter
                "false", // advertise
                null, // advertiseURI
                null // config
            );

        ConsoleAppender consoleAppender = ConsoleAppender.createAppender(
            PatternLayout.createLayout(
                "%-5p - [%d] - [%t] - [%l]  : %m%n", null,
                null, Charset.forName("UTF-8"), true, true, apiKey, apiKey), null, null,
            "Console", null, null);

        appender.start();
        consoleAppender.stop();
        logger.getContext().getConfiguration().getLoggerConfig(apiKey)
            .addAppender(appender, Level.TRACE, null);
        logger.getContext().getConfiguration().getLoggerConfig(apiKey)
            .addAppender(consoleAppender, Level.OFF, null);
        return logger;
    }
}
</code>```

code used to write SOAP request / response to file is as follows :

```<code>SalesCustomerSelectService customerService = new SalesCustomerSelectService(wsdlURL, SERVICE_NAME);
        SalesCustomerSelect customerPort = customerService.getPort(SERVICE_NAME1, SalesCustomerSelect.class);
        if (isLogging()) {
            Client client = ClientProxy.getClient(customerPort);
            client.getInInterceptors().add(new LoggingInInterceptor());
            client.getOutInterceptors().add(new LoggingOutInterceptor());
        }
</code>```

But not sure how to write SOAP request/response in separate log files dynamically.

答:
You could write your own custom Interceptor in which you log the SOAP request/response to their respective log file.

Looks like you are using Apache CXF. The documentation contains a section on writing custom Interceptors. In addition you can checkout following example.

ContentLicense: CC BY-SA 4.0

Body:
Need to write separate log files based on an apikey using log4j2 for SOAP request and response. we are client side or consuming SOAP webservice.

I am able to write separate log files based on an apikey for REST request & response but not sure how to do for SOAP request & response

code to write logs in separate log files is as follows

Need to write separate log files based on an apikey using log4j2 for SOAP request and response. we are client side or consuming SOAP webservice.

I am able to write separate log files based on an apikey for REST request & response but not sure how to do for SOAP request & response

code to write logs in separate log files is as follows :

public final class SPRestLog4j2Logger extends org.apache.logging.log4j.core.async.AsyncLogger {

    private SPRestLog4j2Logger(LoggerContext context, String name, MessageFactory msgFactory) {
        super(context, name, msgFactory);
        this.setLevel(Level.ALL);
    }

    public static SPRestLog4j2Logger configureCategoryLogger(String apiKey, String loggingPath) {
        LoggerContext context = new AsyncLoggerContext(apiKey);
        MessageFactory msgFactory = new FormattedMessageFactory();
        SPRestLog4j2Logger logger = new SPRestLog4j2Logger(context, apiKey, msgFactory);

        RandomAccessFileAppender appender = RandomAccessFileAppender
            .createAppender(
                loggingPath + apiKey + ".log", // filename
                "true", // append
                "file_appender-" + apiKey, // name
                "true", // immediateFlush
                "", // bufferSize
                "true", // ignoreExceptions
                PatternLayout.createLayout(
                    "%-5p - [%d] - [%t] - [%l]  : %m%n", null,
                    null, Charset.forName("UTF-8"), true, true, apiKey, apiKey), null, // filter
                "false", // advertise
                null, // advertiseURI
                null // config
            );

        ConsoleAppender consoleAppender = ConsoleAppender.createAppender(
            PatternLayout.createLayout(
                "%-5p - [%d] - [%t] - [%l]  : %m%n", null,
                null, Charset.forName("UTF-8"), true, true, apiKey, apiKey), null, null,
            "Console", null, null);

        appender.start();
        consoleAppender.stop();
        logger.getContext().getConfiguration().getLoggerConfig(apiKey)
            .addAppender(appender, Level.TRACE, null);
        logger.getContext().getConfiguration().getLoggerConfig(apiKey)
            .addAppender(consoleAppender, Level.OFF, null);
        return logger;
    }
}

code used to write SOAP request / response to file is as follows :

SalesCustomerSelectService customerService = new SalesCustomerSelectService(wsdlURL, SERVICE_NAME);
        SalesCustomerSelect customerPort = customerService.getPort(SERVICE_NAME1, SalesCustomerSelect.class);
        if (isLogging()) {
            Client client = ClientProxy.getClient(customerPort);
            client.getInInterceptors().add(new LoggingInInterceptor());
            client.getOutInterceptors().add(new LoggingOutInterceptor());
        }

But not sure how to write SOAP request/response in separate log files dynamically.


问:
I'm getting an unusual error when I'm trying to start my react app. It says that CleanWebpackPlugin is not a constructor
So, I have made a react app before with the same kind of configuration for webpack but this is the first time I am seeing this. The clean webpack plugin is showing that the class doesn't has a constructor even when it does.

I tried to see if there were any import problems or something like that but everything checks out.

```<code>const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: {
    app: './src/index.js',
    style: './src/style.less'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      },
      {
          test: /\.less$/,
          use: [{
              loader: 'style-loader'
          },
          {
              loader: 'css-loader'
          },
          {
              loader: 'less-loader'
          }
        ]
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      template: './public/index.html'
    }),
  ],
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist')
  }
};
</code>```

Here's the error that I get on my terminal

new CleanWebpackPlugin(),
    ^

TypeError: CleanWebpackPlugin is not a constructor

答:
Check your version.

the latest version of clean-webpack-plugin is 3.0.0 and the usage is

```<code>const {CleanWebpackPlugin} = require('clean-webpack-plugin');
</code>```

the previous version of clean-webpack-plugin is 2.0.2 and the usage is

```<code>const CleanWebpackPlugin = require('clean-webpack-plugin');
</code>```

Body:
So, I have made a react app before with the same kind of configuration for webpack but this is the first time I am seeing this. The clean webpack plugin is showing that the class doesn't has a constructor even when it does.

I tried to see if there were any import problems or something like that but everything checks out.

const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: {
    app: './src/index.js',
    style: './src/style.less'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      },
      {
          test: /\.less$/,
          use: [{
              loader: 'style-loader'
          },
          {
              loader: 'css-loader'
          },
          {
              loader: 'less-loader'
          }
        ]
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      template: './public/index.html'
    }),
  ],
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist')
  }
};

Here's the error that I get on my terminal

new CleanWebpackPlugin(),
    ^

TypeError: CleanWebpackPlugin is not a constructor

Body:
Check your version.

the latest version of clean-webpack-plugin is 3.0.0 and the usage is

const {CleanWebpackPlugin} = require('clean-webpack-plugin');

the previous version of clean-webpack-plugin is 2.0.2 and the usage is

const CleanWebpackPlugin = require('clean-webpack-plugin');


问:
Unable to delete some csv file conditionally
I've written a script in python to get some tabular content from a webpage and write the same in a csv file. What I wish to do now is let my script write the content in a csv file only if the table (visible as Top Mutual Fund Holders) is available in that page otherwise it will remove the csv file that has been created.

The table is avaible in this webpage.

The table I'm looking for is not available in this webpage.

This is my try:

```<code>import os
import csv
import requests
from bs4 import BeautifulSoup

url = "https://finance.yahoo.com/quote/UBER/holders?p=UBER"

def get_mutual_fund(soup):
    datalist = []
    for items in soup.select_one("h3:contains('Top Mutual Fund Holders')").find_next_sibling().select("table tr"):
        data = [item.text for item in items.select("th,td")]
        datalist.append(data)
    return datalist

def get_records(link):
    r = requests.get(link)
    soup_obj = BeautifulSoup(r.text,"lxml")
    try:
        item_one = get_mutual_fund(soup_obj)
    except AttributeError:
        item_one = ""

    if item_one:
        writer.writerows(item_one)
    else:
        os.remove("mutual_fund.csv")
    return item_one

if __name__ == '__main__':
    with open("mutual_fund.csv","w",newline="") as f:
        writer = csv.writer(f)
        for elem in get_records(url):
            print(elem)
</code>```

I've tried with the link that do not have that table. However, it throws the following error

```<code>while deleting the csv file:
Traceback (most recent call last):
  File "C:\Users\WCS\AppData\Local\Programs\Python\Python37-32\demo.py", line 33, in <module>
    for elem in get_records(url):
  File "C:\Users\WCS\AppData\Local\Programs\Python\Python37-32\demo.py", line 27, in get_records
    os.remove("mutual_fund.csv")
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'mutual_fund.csv'
</code>```

How can I delete the csv file when the tabular content is not present?

答:
You are actually deleting the file when it is open to write.

You should change your main function accordingly.

```<code>def get_records(link):
    r = requests.get(link)
    soup_obj = BeautifulSoup(r.text,"lxml")
    try:
        item_one = get_mutual_fund(soup_obj)
    except AttributeError:
        item_one = None
    return item_one

if __name__ == '__main__':
    delete_file= False
    with open("mutual_fund.csv","w",newline="") as f:
        writer = csv.writer(f)
        try:
            for elem in get_records(url):
                print(elem)
        except TypeError:
            delete_file=True
    if delete_file:
        os.remove("mutual_fund.csv")

</code>```

Body:
I've written a script in python to get some tabular content from a webpage and write the same in a csv file. What I wish to do now is let my script write the content in a csv file only if the table (visible as Top Mutual Fund Holders) is available in that page otherwise it will remove the csv file that has been created.

The table is avaible in this webpage.

The table I'm looking for is not available in this webpage.

This is my try:

import os
import csv
import requests
from bs4 import BeautifulSoup

url = "https://finance.yahoo.com/quote/UBER/holders?p=UBER"

def get_mutual_fund(soup):
    datalist = []
    for items in soup.select_one("h3:contains('Top Mutual Fund Holders')").find_next_sibling().select("table tr"):
        data = [item.text for item in items.select("th,td")]
        datalist.append(data)
    return datalist

def get_records(link):
    r = requests.get(link)
    soup_obj = BeautifulSoup(r.text,"lxml")
    try:
        item_one = get_mutual_fund(soup_obj)
    except AttributeError:
        item_one = ""

    if item_one:
        writer.writerows(item_one)
    else:
        os.remove("mutual_fund.csv")
    return item_one

if __name__ == '__main__':
    with open("mutual_fund.csv","w",newline="") as f:
        writer = csv.writer(f)
        for elem in get_records(url):
            print(elem)

I've tried with the link that do not have that table. However, it throws the following error

while deleting the csv file:
Traceback (most recent call last):
  File "C:\Users\WCS\AppData\Local\Programs\Python\Python37-32\demo.py", line 33, in <module>
    for elem in get_records(url):
  File "C:\Users\WCS\AppData\Local\Programs\Python\Python37-32\demo.py", line 27, in get_records
    os.remove("mutual_fund.csv")
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'mutual_fund.csv'

How can I delete the csv file when the tabular content is not present?

Body:
You are actually deleting the file when it is open to write.

You should change your main function accordingly.

def get_records(link):
    r = requests.get(link)
    soup_obj = BeautifulSoup(r.text,"lxml")
    try:
        item_one = get_mutual_fund(soup_obj)
    except AttributeError:
        item_one = None
    return item_one

if __name__ == '__main__':
    delete_file= False
    with open("mutual_fund.csv","w",newline="") as f:
        writer = csv.writer(f)
        try:
            for elem in get_records(url):
                print(elem)
        except TypeError:
            delete_file=True
    if delete_file:
        os.remove("mutual_fund.csv")


问:
Pandas series group by calculate percentage
I have a data frame. I have grouped a column status by date using

```<code>y = news_dataframe.groupby(by=[news_dataframe['date'].dt.date,news_dataframe['status']])['status'].count()
</code>```

and my output is --

```<code>date         status            count
2019-05-29   selected           24
             rejected auto     243
             waiting           109
             no action         1363
2019-05-30   selected           28
             rejected auto     188
             waiting           132
             no action         1249
             repeat              3
2019-05-31   selected           13
             rejected auto       8
             waiting             23
             no action          137
             repeat              2
             source              1
Name: reasonForReject, dtype: int64
</code>```

Now I want to calculate the percentage of each status group by date. How can I achieve this using pandas dataframe?

答:
try this:

```<code># just fill the consecutive rows with this
df=df.ffill()
df.df1.columns=['date','status','count']
# getting the total value of count with date and status
df1=df.groupby(['date']).sum().reset_index()
#renaming it to total as it is the sum
df1.columns=['date','status','total']

# now join the tables to find the total and actual value together
df2=df.merge(df1,on=['date'])

#calculate the percentage
df2['percentage']=(df2.count/df2.total)*100
</code>```

If you need one liner its:

```<code>df['percentage']=(df.ffill()['count]/df.ffill().groupby(['date']).sum().reset_index().rename(columns={'count': 'total'}).merge(df,on=['date'])['total'])*100
</code>```

Body:
I have a data frame. I have grouped a column status by date using

y = news_dataframe.groupby(by=[news_dataframe['date'].dt.date,news_dataframe['status']])['status'].count()

and my output is --

date         status            count
2019-05-29   selected           24
             rejected auto     243
             waiting           109
             no action         1363
2019-05-30   selected           28
             rejected auto     188
             waiting           132
             no action         1249
             repeat              3
2019-05-31   selected           13
             rejected auto       8
             waiting             23
             no action          137
             repeat              2
             source              1
Name: reasonForReject, dtype: int64

Now I want to calculate the percentage of each status group by date. How can I achieve this using pandas dataframe?

Body:
try this:

# just fill the consecutive rows with this
df=df.ffill()
df.df1.columns=['date','status','count']
# getting the total value of count with date and status
df1=df.groupby(['date']).sum().reset_index()
#renaming it to total as it is the sum
df1.columns=['date','status','total']

# now join the tables to find the total and actual value together
df2=df.merge(df1,on=['date'])

#calculate the percentage
df2['percentage']=(df2.count/df2.total)*100

If you need one liner its:

df['percentage']=(df.ffill()['count]/df.ffill().groupby(['date']).sum().reset_index().rename(columns={'count': 'total'}).merge(df,on=['date'])['total'])*100


问:
Binary XML file line #15: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f030003 a=-1}
I was building up a calculator app on Android Studio. When I ran the app on Android  Pie device, the following fatal error occurred. As I am new to Android development, I didn't carry on as soon as the error occurred, the main function of the calculator isn't included in the java file.

[logcat]

```<code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.calculator/com.example.calculator.MainActivity}: android.view.InflateException: Binary XML file line #15: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f030003 a=-1}
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3037)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6863)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: android.view.InflateException: Binary XML file line #15: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f030003 a=-1}
 Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f030003 a=-1}
    at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:794)
    at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:7767)
    at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:7958)
    at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1997)
    at android.support.design.widget.AppBarLayout$LayoutParams.<init>(AppBarLayout.java:743)
    at android.support.design.widget.AppBarLayout.generateLayoutParams(AppBarLayout.java:366)
    at android.support.design.widget.AppBarLayout.generateLayoutParams(AppBarLayout.java:110)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303)
    at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
    at com.example.calculator.MainActivity.onCreate(MainActivity.java:26)
    at android.app.Activity.performCreate(Activity.java:7149)
    at android.app.Activity.performCreate(Activity.java:7140)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1288)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3017)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6863)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
</code>```

and in main activity,

```<code>    package com.example.calculator;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.example.calculator.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;

    private double valueOne, valueTwo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
//        setContentView(R.layout.activity_main);
//        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        setSupportActionBar(toolbar);
//
//        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
//        fab.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
//                        .setAction("Action", null).show();
//            }
//        });
        // Mr. Rigby
        // Steven, test

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, 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_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
</code>```

and what's in the corresponding activity_main.xml file is

```<code>    <?xml version="1.0" encoding="utf-8"?>
<layout>
    <android.support.design.widget.CoordinatorLayout 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=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_dialog_email" />

    </android.support.design.widget.CoordinatorLayout>
</layout>
</code>```

and finally what's in content_main.xml is

```<code>    <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    android:importantForAutofill="no"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MainActivity"
    tools:showIn="@layout/activity_main">

    <Button
        android:id="@+id/bt_plus"
        style="@style/Widget.MaterialComponents.Button.TextButton"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_marginStart="21dp"
        android:layout_marginTop="57dp"
        android:fontFamily="monospace"
        android:text="@string/button_plus"
        android:textSize="30sp"
        android:typeface="normal"
        app:layout_constraintEnd_toStartOf="@+id/bt_minus"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tb_valueA" />

    <Button
        android:id="@+id/bt_minus"
        style="@style/Widget.MaterialComponents.Button.TextButton"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_marginStart="24dp"
        android:layout_marginTop="57dp"
        android:fontFamily="monospace"
        android:text="@string/button_minus"
        android:textSize="30sp"
        android:typeface="normal"
        app:layout_constraintEnd_toStartOf="@+id/bt_multiply"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/bt_plus"
        app:layout_constraintTop_toBottomOf="@+id/tb_valueA" />

    <Button
        android:id="@+id/bt_multiply"
        style="@style/Widget.MaterialComponents.Button.TextButton"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_marginStart="24dp"
        android:layout_marginTop="57dp"
        android:fontFamily="monospace"
        android:text="@string/button_multiply"
        android:textSize="30sp"
        android:typeface="normal"
        app:layout_constraintEnd_toStartOf="@+id/bt_divide"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/bt_minus"
        app:layout_constraintTop_toBottomOf="@+id/tb_valueB" />

    <Button
        android:id="@+id/bt_divide"
        style="@style/Widget.MaterialComponents.Button.TextButton"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_marginStart="20dp"
        android:layout_marginTop="57dp"
        android:layout_marginEnd="16dp"
        android:fontFamily="monospace"
        android:text="@string/button_divide"
        android:textSize="30sp"
        android:typeface="normal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/bt_multiply"
        app:layout_constraintTop_toBottomOf="@+id/tb_valueB" />

    <EditText
        android:id="@+id/tb_valueA"
        android:layout_width="0dp"
        android:layout_height="44dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="158dp"
        android:layout_marginEnd="12dp"
        android:ems="10"
        android:fontFamily="serif-monospace"
        android:hint="@string/valueA"
        android:importantForAutofill="no"
        android:inputType="numberDecimal"
        android:text="@string/valueA"
        android:textColor="@android:color/holo_orange_dark"
        android:textSize="24sp"
        android:typeface="monospace"
        app:layout_constraintEnd_toStartOf="@+id/tb_valueB"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/tb_valueB"
        android:layout_width="0dp"
        android:layout_height="44dp"
        android:layout_marginTop="158dp"
        android:layout_marginEnd="16dp"
        android:ems="10"
        android:fontFamily="serif-monospace"
        android:hint="@string/valueB"
        android:importantForAutofill="no"
        android:inputType="numberDecimal"
        android:text="@string/valueB"
        android:textColor="@android:color/holo_red_dark"
        android:textSize="24sp"
        android:typeface="monospace"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/tb_valueA"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv_result"
        android:layout_width="155dp"
        android:layout_height="50dp"
        android:layout_marginStart="206dp"
        android:layout_marginTop="68dp"
        android:layout_marginEnd="23dp"
        android:layout_marginBottom="132dp"
        android:fontFamily="serif-monospace"
        android:text="@string/result"
        android:textSize="30sp"
        android:typeface="monospace"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.222"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/bt_multiply"
        app:layout_constraintVertical_bias="0.962" />

</android.support.constraint.ConstraintLayout>
</code>```

答:
I don't know if this helps but you should check your app theme in your styles.xml file. If you have changed it, you have changed it to one that is not compatible with your activity which from what I can see, seems to be a "basic activity" format.

Try changing it to one that descends from Theme.AppCompat for starters. Also, don't forget the define this too and use it on your activity in the android manifest

```<code><style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
</code>```

As for a fix that allows you to keep your theme and solve the problem. I will get back to you on that.

Body:
I was building up a calculator app on Android Studio. When I ran the app on Android  Pie device, the following fatal error occurred. As I am new to Android development, I didn't carry on as soon as the error occurred, the main function of the calculator isn't included in the java file.

[logcat]

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.calculator/com.example.calculator.MainActivity}: android.view.InflateException: Binary XML file line #15: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f030003 a=-1}
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3037)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6863)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: android.view.InflateException: Binary XML file line #15: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f030003 a=-1}
 Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f030003 a=-1}
    at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:794)
    at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:7767)
    at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:7958)
    at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1997)
    at android.support.design.widget.AppBarLayout$LayoutParams.<init>(AppBarLayout.java:743)
    at android.support.design.widget.AppBarLayout.generateLayoutParams(AppBarLayout.java:366)
    at android.support.design.widget.AppBarLayout.generateLayoutParams(AppBarLayout.java:110)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303)
    at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
    at com.example.calculator.MainActivity.onCreate(MainActivity.java:26)
    at android.app.Activity.performCreate(Activity.java:7149)
    at android.app.Activity.performCreate(Activity.java:7140)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1288)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3017)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6863)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

and in main activity,

    package com.example.calculator;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.example.calculator.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;

    private double valueOne, valueTwo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
//        setContentView(R.layout.activity_main);
//        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        setSupportActionBar(toolbar);
//
//        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
//        fab.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
//                        .setAction("Action", null).show();
//            }
//        });
        // Mr. Rigby
        // Steven, test

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, 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_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

and what's in the corresponding activity_main.xml file is

    <?xml version="1.0" encoding="utf-8"?>
<layout>
    <android.support.design.widget.CoordinatorLayout 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=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_dialog_email" />

    </android.support.design.widget.CoordinatorLayout>
</layout>

and finally what's in content_main.xml is

    <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    android:importantForAutofill="no"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MainActivity"
    tools:showIn="@layout/activity_main">

    <Button
        android:id="@+id/bt_plus"
        style="@style/Widget.MaterialComponents.Button.TextButton"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_marginStart="21dp"
        android:layout_marginTop="57dp"
        android:fontFamily="monospace"
        android:text="@string/button_plus"
        android:textSize="30sp"
        android:typeface="normal"
        app:layout_constraintEnd_toStartOf="@+id/bt_minus"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tb_valueA" />

    <Button
        android:id="@+id/bt_minus"
        style="@style/Widget.MaterialComponents.Button.TextButton"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_marginStart="24dp"
        android:layout_marginTop="57dp"
        android:fontFamily="monospace"
        android:text="@string/button_minus"
        android:textSize="30sp"
        android:typeface="normal"
        app:layout_constraintEnd_toStartOf="@+id/bt_multiply"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/bt_plus"
        app:layout_constraintTop_toBottomOf="@+id/tb_valueA" />

    <Button
        android:id="@+id/bt_multiply"
        style="@style/Widget.MaterialComponents.Button.TextButton"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_marginStart="24dp"
        android:layout_marginTop="57dp"
        android:fontFamily="monospace"
        android:text="@string/button_multiply"
        android:textSize="30sp"
        android:typeface="normal"
        app:layout_constraintEnd_toStartOf="@+id/bt_divide"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/bt_minus"
        app:layout_constraintTop_toBottomOf="@+id/tb_valueB" />

    <Button
        android:id="@+id/bt_divide"
        style="@style/Widget.MaterialComponents.Button.TextButton"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_marginStart="20dp"
        android:layout_marginTop="57dp"
        android:layout_marginEnd="16dp"
        android:fontFamily="monospace"
        android:text="@string/button_divide"
        android:textSize="30sp"
        android:typeface="normal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/bt_multiply"
        app:layout_constraintTop_toBottomOf="@+id/tb_valueB" />

    <EditText
        android:id="@+id/tb_valueA"
        android:layout_width="0dp"
        android:layout_height="44dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="158dp"
        android:layout_marginEnd="12dp"
        android:ems="10"
        android:fontFamily="serif-monospace"
        android:hint="@string/valueA"
        android:importantForAutofill="no"
        android:inputType="numberDecimal"
        android:text="@string/valueA"
        android:textColor="@android:color/holo_orange_dark"
        android:textSize="24sp"
        android:typeface="monospace"
        app:layout_constraintEnd_toStartOf="@+id/tb_valueB"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/tb_valueB"
        android:layout_width="0dp"
        android:layout_height="44dp"
        android:layout_marginTop="158dp"
        android:layout_marginEnd="16dp"
        android:ems="10"
        android:fontFamily="serif-monospace"
        android:hint="@string/valueB"
        android:importantForAutofill="no"
        android:inputType="numberDecimal"
        android:text="@string/valueB"
        android:textColor="@android:color/holo_red_dark"
        android:textSize="24sp"
        android:typeface="monospace"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/tb_valueA"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv_result"
        android:layout_width="155dp"
        android:layout_height="50dp"
        android:layout_marginStart="206dp"
        android:layout_marginTop="68dp"
        android:layout_marginEnd="23dp"
        android:layout_marginBottom="132dp"
        android:fontFamily="serif-monospace"
        android:text="@string/result"
        android:textSize="30sp"
        android:typeface="monospace"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.222"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/bt_multiply"
        app:layout_constraintVertical_bias="0.962" />

</android.support.constraint.ConstraintLayout>

Body:
I don't know if this helps but you should check your app theme in your styles.xml file. If you have changed it, you have changed it to one that is not compatible with your activity which from what I can see, seems to be a "basic activity" format.

Try changing it to one that descends from Theme.AppCompat for starters. Also, don't forget the define this too and use it on your activity in the android manifest

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

As for a fix that allows you to keep your theme and solve the problem. I will get back to you on that.


问:
Next greatest number
I'm trying to find the next greatest number from the user input.If the user gives 23 it shows the output as 32.If there is number greater number then it has to print the same given number.But if the user gives 03 it shows 3 but it has to show 30.Because it takes 03 as octal number.How can i change the code to show the correct output as 30?</p>

```<code>public class Main
{
 static void swap(char ar[], int i, int j)
 {
  char temp = ar[i];
  ar[i] = ar[j];
  ar[j] = temp;
 }
 public static void main(String[] args)
 {
   Scanner in = new Scanner(System.in);
   int num = in .nextInt();
   char[] chars = ("" + num).toCharArray();
   int i;
   int n = chars.length;
   for (i = n - 1; i > 0; i--)
   {
    if (chars[i] > chars[i - 1])
     break;
   }
   if (i == 0)
    System.out.println(num);
   else {
    int x = chars[i - 1], min = i;
   for (int j = i + 1; j<n; j++)
   {
    if (chars[j] > x && chars[j]<chars[min])
     min = j;
   }
   swap(chars, i - 1, min);
   Arrays.sort(chars, i, n);
   for (i = 0; i<n; i++)
     System.out.print(chars[i]);
  }
 }
}
</code>```

答:
In your main(),take the input as String only, instead of taking it as integer.
String num=in.next();

Title: Next greatest number

Body:
I'm trying to find the next greatest number from the user input.If the user gives 23 it shows the output as 32.If there is number greater number then it has to print the same given number.But if the user gives 03 it shows 3 but it has to show 30.Because it takes 03 as octal number.How can i change the code to show the correct output as 30?

public class Main
{
 static void swap(char ar[], int i, int j)
 {
  char temp = ar[i];
  ar[i] = ar[j];
  ar[j] = temp;
 }
 public static void main(String[] args)
 {
   Scanner in = new Scanner(System.in);
   int num = in .nextInt();
   char[] chars = ("" + num).toCharArray();
   int i;
   int n = chars.length;
   for (i = n - 1; i > 0; i--)
   {
    if (chars[i] > chars[i - 1])
     break;
   }
   if (i == 0)
    System.out.println(num);
   else {
    int x = chars[i - 1], min = i;
   for (int j = i + 1; j<n; j++)
   {
    if (chars[j] > x && chars[j]<chars[min])
     min = j;
   }
   swap(chars, i - 1, min);
   Arrays.sort(chars, i, n);
   for (i = 0; i<n; i++)
     System.out.print(chars[i]);
  }
 }
}