I want to keep a record

Backendless.initApp(this, APPI_ID, SECRET_KEY, VERSION); Customer melinda = new Customer(); melinda.setFirstName( "Melinda" ); melinda.setLastName( "Grey" ); Backendless.Persistence.of(Customer.class).save(melinda, new AsyncCallback<Customer>() { @Override public void handleResponse(Customer response) { } @Override public void handleFault(BackendlessFault fault) { } }); System.out.println("Melinda's rate is "+melinda.getDiscountRatePercent()+"percent"); melinda.setDiscountRatePercent( melinda.getDiscountRatePercent() + 2 ); Backendless.Persistence.of(Customer.class).save(melinda, new AsyncCallback<Customer>() { @Override public void handleResponse(Customer customer) { } @Override public void handleFault(BackendlessFault fault) { } }); Customer updatedMelinda = new Customer(); updatedMelinda.setFirstName( "Melinda" ); updatedMelinda.setLastName( "Grey" ); updatedMelinda = Backendless.Persistence.of( Customer.class ).findById ( updatedMelinda ); System.out.println("Now Melinda's discount rate is "+updatedMelinda. getDiscountRatePercent() +" percent."); } } 

Java swears

10-22 03: 14: 23.620 2774-2774 /? E / AndroidRuntime: FATAL EXCEPTION: main Process: com.example.elvir.subdexample, PID: 2774 java.lang.RuntimeException: Unable to set activity ComponentInfo {com.example.elvir.subdexample / com.example.elvir.subdexample.MainActivity }: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2195) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2245) at android.app.ActivityThread.access $ 800 (ActivityThread.java:2245) : 135) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1196) at android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:136) at android.app.ActivityThread.main (ActivityThread.java Dep017) at java.lang.reflect.Method.invokeNative (Native Method) at java.lang.reflect.Method.invoke (Method.java Zin15) at com.android .internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main (ZygoteInit.javament95) at dalvik.system.NativeStart. main (Native Method) Caused by: java.lang.NullPointerException at com.example.elvir.subdexample.MainActivity.onCreate (MainActivity.java:40) at android.app.Activity.performCreate (Activity.java Fl231) at android. app.Instrumentation.callActivityOnCreate (Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2159) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2245) at android.app.ActivityThread.access $ 800 (ActivityThread.java:135) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1196) at android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper .java: 136) at android.app.ActivityThread.main (ActivityThread.javaive017) at java.lang.reflect.Method.invokeNative (Native Method) at java.lang.reflect.Method.invoke (Method.java Incre15 ) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java partner95) at dalvik.system .NativeStart.main (Native Method)

    1 answer 1

    It's easier for you to look through the debugger. I dare to suggest that the problem is in this stock

     System.out.println("Now Melinda's discount rate is "+updatedMelinda. getDiscountRatePercent() +" percent."); 

    because

      updatedMelinda = Backendless.Persistence.of( Customer.class ).findById ( updatedMelinda ); 

    updatedMelinda is null because findById( updatedMelinda ); obviously implies that you must specify an object of type int , and not Customer

    • yes there also gives an error and how to specify int? - elik
    • "percent" replaice by + o ~ int? - elik
    • updatedMelinda = Backendless.Persistence.of( Customer.class ).findById(1) like this, for example. Or use not findById - ArchDemon