dimanche 21 juin 2015

Having problems Inserting values

I am trying to insert values in an SQlite database when a user enters values in a user form. But am not sure where I am going wrong

On pressing the Submit button I am getting the below error log.

25049-25049/com.example.nfcams E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.nfcams, PID: 25049
    java.lang.IllegalStateException: Could not execute method of the activity
            at android.view.View$1.onClick(View.java:3969)
            at android.view.View.performClick(View.java:4633)
            at android.view.View$PerformClick.run(View.java:19330)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5356)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.view.View$1.onClick(View.java:3964)
            at android.view.View.performClick(View.java:4633)
            at android.view.View$PerformClick.run(View.java:19330)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5356)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.example.nfcams.AddingAssetsActivity.SaveAssets(AddingAssetsActivity.java:252)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.view.View$1.onClick(View.java:3964)
            at android.view.View.performClick(View.java:4633)
            at android.view.View$PerformClick.run(View.java:19330)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5356)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)

The insert method can be found below

 public void InsertAssets(Assets assets)
    {
        // writing values to the Database
        SQLiteDatabase db_database = getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(ASSET_Name,assets.getAssetName());
        values.put(ASSET_Category,assets.getCategory());
        values.put(CUSTODIAN_ID,assets.getCustodianID());
        values.put(Asset_Cost,assets.getCostofAsset());
        values.put(ASSET_PurchaseDate,formatter.format(assets.getPurchase()));
        values.put(ASSET_STATUS,assets.getStatus());
        values.put(ASSET_Warrenty,formatter.format(assets.getWarrenty()));

        //Inserting it to the Database
        db_database.insert(ASSETTAB,null,values);
        db_database.close();
    }

The an Onclick method can be found below

public void SaveAssets(View v)
        {

                 Assets addingassets = new Assets(handler.getassetcount(),String.valueOf(AssetName.getText()),String.valueOf(Custodianid.getText()),String.valueOf(AssetCat.getText()),selected_values,costofasset,warent,Purch_var);

                 handler.InsertAssets(addingassets);

             }

Aucun commentaire:

Enregistrer un commentaire