0

Androidで独自のアプリケーションを開発しようとしており、情報をDBに更新したいので、ここに私のコード /////////DB//////////

//-- レコードを更新する --

public boolean updateRecords(long columnId, String nAME ,String sURNAME,String dateOfBirth, String homeAddress,String emailNO, String phoneNumber, String city,String type_payment, String type_shipping,String cardNumber,String username, String passwords )




     {

        ContentValues args = new ContentValues();

            args.put(COLUMN_NAME,nAME);
            args.put(COLUMN_SURNAME,sURNAME);
            args.put(COLUMN_DATE_OF_BIRTH,dateOfBirth);
            args.put(COLUMN_ADDRESS,homeAddress);
            args.put(COLUMN_EMAIL,emailNO);
            args.put(COLUMN_PHONE_NUMBER,phoneNumber);
            args.put(COLUMN_CITY,city);
            args.put(COLUMN_PTYE_PAYMENT,type_payment);
            args.put(COLUMN_SHIPPING_TYPE,type_shipping);
            args.put(COLUMN_CARD_NUMBER,cardNumber);
            args.put(COLUMN_username,username); 
            args.put(COLUMN_Password,passwords);





    return db.update(USERS_TABLE, args,COLUMN_ID + "= "+ columnId, null) > 0;

            }

そして、私のACTIVITY CLASSはこんな感じです........

public void onClick(View v) {
        if(v.getId() == R.id.btnEditSave){

        Log.d("test", "edited");     

//get data from form


 EditText NAME = (EditText)findViewById(R.id.editTxtname);
   EditText SURNAME = (EditText)findViewById(R.id.editTxtSurname);
   EditText DateOfBirth = (EditText)findViewById(R.id.editTxtID);
    EditText HomeAddress = (EditText)findViewById(R.id.editTxtPAddress);
   EditText EmailNO = (EditText)findViewById(R.id.editTxtEmail);
   EditText PhoneNumber = (EditText)findViewById(R.id.editTxtNumber);
   EditText City = (EditText)findViewById(R.id.editTxtCity);
   EditText type_payment = (EditText)findViewById(R.id.editTextspinnerPayment);
  EditText type_shipping = (EditText)findViewById(R.id.editTextSpinnerShipping);
   EditText CardNumber = (EditText)findViewById(R.id.editTxtCardNumber);



EditText Username = (EditText)findViewById(R.id.editTxtUsername);
   EditText Passwords = (EditText)findViewById(R.id.editTxtPassword);




Cursor value = null ;
    db.open();
    Log.d("test", "opened database"); 

    long columnId = value.getLong(value.getColumnIndex("ID"));
    //boolean
    if( db.updateRecords(columnId, NAME.getText().toString(),
                         SURNAME.getText().toString(),
                         DateOfBirth.getText().toString(),
                         HomeAddress.getText().toString(),
                         EmailNO.getText().toString(),
                         PhoneNumber.getText().toString(), 
                         City.getText().toString(), 
                         type_payment.getText().toString(),
                         type_shipping.getText().toString(),
                         CardNumber.getText().toString(), 
                         Username.getText().toString(),
                         Passwords.getText().toString())); 


              else
              {
    Toast.makeText(this,"Failed",Toast.LENGTH_LONG).show();

              }

db.close();

そして、ログキャストでエラーが発生しています.......

06-02 16:29:48.518: D/dalvikvm(12573): GC_CONCURRENT freed 6K, 5% free 7179K/7495K, paused 7ms+5ms
06-02 16:30:03.218: D/test(12573): edited
06-02 16:30:03.278: D/test(12573): opened database
06-02 16:30:03.278: D/AndroidRuntime(12573): Shutting down VM
06-02 16:30:03.278: W/dalvikvm(12573): threadid=1: thread exiting with uncaught exception (group=0x40014760)
06-02 16:30:03.320: E/AndroidRuntime(12573): FATAL EXCEPTION: main
06-02 16:30:03.320: E/AndroidRuntime(12573): java.lang.NullPointerException
06-02 16:30:03.320: E/AndroidRuntime(12573):    at com.sdc.editpersonalinfo.onClick(editpersonalinfo.java:119)
06-02 16:30:03.320: E/AndroidRuntime(12573):    at android.view.View.performClick(View.java:3110)
06-02 16:30:03.320: E/AndroidRuntime(12573):    at android.view.View$PerformClick.run(View.java:11928)
06-02 16:30:03.320: E/AndroidRuntime(12573):    at android.os.Handler.handleCallback(Handler.java:587)
06-02 16:30:03.320: E/AndroidRuntime(12573):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-02 16:30:03.320: E/AndroidRuntime(12573):    at android.os.Looper.loop(Looper.java:132)
06-02 16:30:03.320: E/AndroidRuntime(12573):    at android.app.ActivityThread.main(ActivityThread.java:4025)
06-02 16:30:03.320: E/AndroidRuntime(12573):    at java.lang.reflect.Method.invokeNative(Native Method)
06-02 16:30:03.320: E/AndroidRuntime(12573):    at java.lang.reflect.Method.invoke(Method.java:491)
06-02 16:30:03.320: E/AndroidRuntime(12573):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
06-02 16:30:03.320: E/AndroidRuntime(12573):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
06-02 16:30:03.320: E/AndroidRuntime(12573):    at dalvik.system.NativeStart.main(Native Method)
06-02 16:35:03.524: I/Process(12573): Sending signal. PID: 12573 SIG: 9
06-02 16:35:05.550: V/TLINE(13716): new: android.text.TextLine@40684488
06-02 16:35:06.151: V/TLINE(13716): new: android.text.TextLine@406894b0
4

1 に答える 1

1

ここでは、「値」を null に初期化してから使用しているため、NullPointerException があると思います。

Cursor value = null ;
db.open();
Log.d("test", "opened database"); 

long columnId = value.getLong(value.getColumnIndex("ID"));

このチュートリアルをご覧になれば、おそらくそれは良い考えです:

http://developer.android.com/resources/tutorials/notepad/index.html

演習 1 では、Android で sqlite データベースを処理する方法について説明します。

于 2012-06-02T14:47:00.337 に答える