T
T
Tamerlan Godzhiev2019-04-23 15:37:14
Android
Tamerlan Godzhiev, 2019-04-23 15:37:14

What is the error when saving the value to the database?

Hello! I'm finishing a small application for accounting for goods. The last step remains. I need to save the values ​​changed in the fields to the database.
5cbf04e97e949594074815.jpeg
Here is my activity code. So far I have written the code for only one button.

public class InnerActivity extends AppCompatActivity {

    private ApparatDatabaseHelper dbHelper = new ApparatDatabaseHelper(this);

    //private ProductsAdapter productsAdapter = new ProductsAdapter();

    public static final String EXTRA_PRODUCT = "extraProduct";




    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.inner_product);



        int idNumber = (Integer)getIntent().getExtras().get(EXTRA_PRODUCT);






        SQLiteDatabase db = dbHelper.getReadableDatabase();

        final Cursor cursor = db.query ("products", null, "id = ?", new String[] { Integer.toString(idNumber+1) }, null, null, null);
        //final Cursor cursor = db.query ("products", null, "id = 1", null, null, null, null);


       final List<Product> products = new ArrayList<>();


        if (cursor.moveToFirst()) {

            //Получение данных напитка из курсора
            String nameText = cursor.getString(1);
            int position = cursor.getInt(2);
            int factCount = cursor.getInt(3);
            int stockCount = cursor.getInt(4);


            TextView name = (TextView) findViewById(R.id.productName);
            name.setText(nameText);

            TextView pos = (TextView) findViewById(R.id.posCount);
            pos.setText(String.valueOf(position));

            TextView fact = (TextView) findViewById(R.id.factAppCount);
            fact.setText(String.valueOf(factCount));

            TextView stock = (TextView) findViewById(R.id.stockCount);
            stock.setText(String.valueOf(stockCount));

        }

        cursor.close();
        }


    public void pluseOneFact(View view) {

        SQLiteDatabase db = dbHelper.getReadableDatabase();
        int productNo = (Integer)getIntent().getExtras().get("productNo");

        // Do something in response to button click
    TextView factPlus = (TextView) findViewById(R.id.factAppCount);
    String newfactplus = factPlus.getText().toString();
    int intNewFact = Integer.valueOf(newfactplus);
    int plusNewFact = intNewFact + 1;
    factPlus.setText(String.valueOf(plusNewFact));
        ContentValues productValues = new ContentValues();
        productValues.put("product", plusNewFact);
        db.update("products", productValues,
                "id = ?", new String[] {Integer.toString(productNo)});
        db.close();


    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timohius, 2019-04-30
@TIMOHIUS

I think for a start you need to throw off the error log itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question