Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8685067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:28:26+00:00 2026-06-12T22:28:26+00:00

Yes I know this question has been ask a lot but it seems that

  • 0

Yes I know this question has been ask a lot but it seems that all the question I’ve check doesn’t solve my problem. So I’ll go straight to the point.

here’s the database class

SQLHandler.java

public class SQLHandler {
    public static final String KEY_ROOMMOVEHOLDER = "roommoveholder";
    public static final String KEY_ROOM = "room";
    public static final String KEY_ROOMWEIGHT = "roomweight";

    public static final String KEY_MOVENAME = "movename";
    public static final String KEY_ID1 = "_id";
    public static final String KEY_ID2 = "_id";

    public static final String KEY_MOVEDATE = "movedate";
    public static final String KEY_TOTALMOVEWEIGHT = "totalmoveweight";
    public static final String KEY_TOTALITEM = "totalitem";

    private static final String DATABASE_NAME = "mymovingfriend";
    private static final int DATABASE_VERSION = 1;

    public static final String KEY_TODOMOVE = "todomove";

    private static final String DATABASE_TABLE1 = "movingname";
    private static final String DATABASE_TABLE2 = "movingrooms";

    public static final String CREATE_TABLE_1 = "CREATE TABLE " + DATABASE_TABLE1 + " (" + 
            KEY_ID1 + " INTEGER PRIMARY KEY AUTOINCREMENT," + 
            KEY_MOVEDATE + " TEXT NOT NULL, " + 
            KEY_TOTALMOVEWEIGHT + " TEXT NOT NULL, " + 
            KEY_TOTALITEM + " INTEGER NOT NULL, " +
            KEY_MOVENAME + " TEXT NOT NULL);";

    public static final String CREATE_TABLE_2 = "CREATE TABLE " + DATABASE_TABLE2 + " (" + 
            KEY_ID2 + " INTEGER PRIMARY KEY AUTOINCREMENT," + 
            KEY_ROOMMOVEHOLDER + " TEXT NOT NULL, " + 
            KEY_ROOMWEIGHT + " TEXT NOT NULL, " + 
            KEY_ROOM + " TEXT NOT NULL);";


    private DbHelper ourHelper;
    private final Context ourContext;
    private SQLiteDatabase ourDatabase;

    private static class DbHelper extends SQLiteOpenHelper{

        public DbHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
            // TODO Auto-generated constructor stub
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            // TODO Auto-generated method stub
            db.execSQL(CREATE_TABLE_1);
            db.execSQL(CREATE_TABLE_2);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldversion, int newversion) {
            // TODO Auto-generated method stub
            db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE1);
            db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE2);
            onCreate(db);
        }
    }

    public SQLHandler(Context c){
        ourContext = c;
    }

    public SQLHandler open() throws SQLException{
        ourHelper = new DbHelper(ourContext);
        ourDatabase = ourHelper.getWritableDatabase();
        return this;
    }

    public void close(){
        ourHelper.close();
    }

    public void renameRoom(String movename, String roomname){
        ContentValues cv = new ContentValues();
        cv.put(KEY_ROOM, roomname);
        ourDatabase.update(DATABASE_TABLE2, cv, KEY_ROOMMOVEHOLDER + "='" + movename + "'" + " AND " + KEY_ROOM + "='" + roomname + "'", null);
    }


}

and this is my activity

StartMoving.java

public class StartMoving extends Activity {

    Button returnBack, addmove, set, setCancel;
    SQLHandler startmoving;

    EditText newMove;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.start_moving);

        initializer();
        itemInitializer();

        Intent i = getIntent();     
        currentMove = i.getStringExtra("moveName");

        buttonLoad();
        currentMoveName.setText(currentMove);

        currentRoom = "None";
        roomName.setText(currentRoom);

        buttonSet();
        itemButton();
        checktodo();
        roomSpinner();      

        SharedPreferences tut_pref = PreferenceManager.getDefaultSharedPreferences(StartMoving.this);
        btut = tut_pref.getString("gettut", "null");

        if (btut.equals("yes")) {
            AlertDialog help1 = new AlertDialog.Builder(StartMoving.this).show();
            help1.setContentView(R.layout.add_room_tut);
            next = true;
            managehelp = true;
            tut_pref = PreferenceManager.getDefaultSharedPreferences(StartMoving.this);
            SharedPreferences.Editor tut = tut_pref.edit();
            tut.putString("gettut", "no");
            tut.commit();
        }else {

        }

    }

    private void buttonLoad() {
        try {

            ArrayList<String> sb = startmoving.loadRooms(currentMove);
            String[] rb = (String[]) sb.toArray(new String[sb.size()]);
            for (int i = 0; i < rb.length; i++) {
                final Button nb = new Button(StartMoving.this);
                nb.setText(rb[i]);
                row.addView(nb);
                nb.setOnClickListener(new OnClickListener() {

                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        currentRoom = nb.getText().toString();
                        roomName.setText(currentRoom);

                        String displayname = startmoving.getItemName(currentMove, currentRoom);
                        String displayvalue = startmoving.getItemValue(currentMove, currentRoom);
                        String displayweight = startmoving.getItemWeightLBS(currentMove, currentRoom);
                        String displaytotalweight = startmoving.getTotalWeightLBS(currentMove);
                        String displayroomweight = startmoving.getRoomWeightLBS(currentMove, currentRoom);
                        int displaytotalitem = startmoving.getTotalItem(currentMove);
                        roomContent.setText(displayname);
                        itemValue.setText(displayvalue);
                        itemWeight.setText(displayweight);
                        totalweight.setText(displaytotalweight);
                        roomweight.setText(displayroomweight);
                        totalitem.setText("" + displaytotalitem);
                    }
                });
            }
            addRooms.addView(row);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private void initializer() {

        startmoving = new SQLHandler(StartMoving.this);
        startmoving.open();

    }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.activity_main, menu);
        return true;
    }

    @SuppressLint("SdCardPath")
    @SuppressWarnings({ "deprecation" })
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        super.onOptionsItemSelected(item);
        boolean retval = true;
        switch (item.getItemId()) {

        case R.id.menu_rename:
            final View view;
            LayoutInflater inf = LayoutInflater.from(StartMoving.this);
            view = inf.inflate(R.layout.rename, null);

            final EditText newname = (EditText) view.findViewById(R.id.etNewRoomName);

            new AlertDialog.Builder(StartMoving.this)
            .setView(view)
            .setTitle("Rename")
            .setMessage("Enter new name for room " + currentRoom)
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    if (currentRoom.equals(newname.getText().toString())) {
                        Toast.makeText(StartMoving.this, "This name is already present. Please enter another name", Toast.LENGTH_LONG).show();
                    }else{
                        try {
                            String newroomname = newname.getText().toString();
                            startmoving.renameRoom(currentMove, newroomname);
//                          Intent intent = getIntent();
//                          finish();
//                          startActivity(intent);
                        } catch (Exception e) {
                            String error = e.toString();
                            Toast.makeText(StartMoving.this, error, Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            })
            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub

                }
            })
            .show();

            break;
        default:
            break;
        }
        return retval;
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        startmoving.close();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        // TODO Auto-generated method stub
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onRestoreInstanceState(savedInstanceState);

        roomName.setText("Hello world");
    }

    public void onBackPressed(){
        super.onBackPressed();

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)  {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            // do something on back.
            if (check == 1) {
                merge.setVisibility(View.GONE);
                main.setVisibility(View.VISIBLE);
                check = 0;
            }else if (check == 2) {
                main.setVisibility(View.VISIBLE);
                roomButtons.setVisibility(View.GONE);
                check = 0;
            }else {
                //              this.finish();
                Intent i = new Intent(StartMoving.this, ListMovingNames.class);
                startActivity(i);
            }
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }
}

can anyone point out what I’ve done wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:28:27+00:00Added an answer on June 12, 2026 at 10:28 pm

    PLease try: (in your close method of DbHelper)

    public void close(){
         ourDatabase.close();
         ourHelper.close();
    }
    

    You need to close your writable db and then close the helper.

    UPDATE Try:

    String[] whereClause = {movename, roomname};
    ourDatabase.update(DATABASE_TABLE2, cv, KEY_ROOMMOVEHOLDER + "=? AND " + KEY_ROOM + "=?", whereClause);
    

    The updaet statements use prepared statements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yes, I know this question has been asked a lot of times, but I
Yes I know, this question has been asked MANY times but after reading all
Yes, I know this question has been asked before, but I can't find an
I know that this question has been asked over and over again but still
Yes, I know that the FAQ pretends to answer this, but it doesn't really.
Yes, I know this question has been asked dozens of times before. However, when
I know this question has been asked before and I read all the answers
I know this is an old question that has been passed around SO several
Hey guys, I don't know if this question has been asked yet but imagine
Yes, I know this question has been asked 1000 times before... here is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.