{"id":2575,"date":"2022-08-30T15:26:00","date_gmt":"2022-08-30T15:26:00","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/03\/how-can-i-combine-the-currentminute-and-currenthour-into-one-text-field-so-it-displays-in-a-normal-time-format-ex-930-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:26:00","modified_gmt":"2022-08-30T15:26:00","slug":"how-can-i-combine-the-currentminute-and-currenthour-into-one-text-field-so-it-displays-in-a-normal-time-format-ex-930-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-can-i-combine-the-currentminute-and-currenthour-into-one-text-field-so-it-displays-in-a-normal-time-format-ex-930-collection-of-common-programming-errors\/","title":{"rendered":"How can I combine the currentMinute and currentHour into one text field so it displays in a normal time format [ex 9:30]-Collection of common programming errors"},"content":{"rendered":"<p>I have an application which stores the CurrentHour and CurrentMinute from a TimePicker in a sqlite database then displays it in another activity ViewCountry java<\/p>\n<p>I would like to combine these two fields in and display them together 9:30 &#8211; for example in the<\/p>\n<pre><code>\n<\/code><\/pre>\n<p>of view_country xml<\/p>\n<pre><code>add_country xml\n=================\n\n        \n        \n\n        \n\n          \n\n          \n\n        \n\n        \n\n        \n\n            \n\n            \n        \n\n        \n\n        \n\n        \n\n            \n\n            \n        \n\n        \n\n         \n\n        \n\n         \n\n          \n        \n        \n\n**ADDEDITCOUNTRY** \n============================\n quite possible minute values from TimePicker here are messing things up\n\n    import android.app.Activity;\n    import android.app.AlertDialog;\n    import android.os.AsyncTask;\n    import android.os.Bundle;\n    import android.view.ViewGroup;\n    import android.view.View;\n    import android.view.View.OnClickListener;\n    import android.widget.Button;\n    import android.widget.EditText;\n    import android.widget.FrameLayout;\n    import android.widget.TimePicker;\n    import android.content.ContentValues;\n    import android.content.Context;\n    import android.database.Cursor;\n    import android.database.SQLException;\n    import android.database.sqlite.SQLiteDatabase;\n    import android.database.sqlite.SQLiteDatabase.CursorFactory;\n    import android.database.sqlite.SQLiteOpenHelper;\n    import android.content.Context;\n\n\n    public class AddEditCountry extends Activity {\n\n         private long rowID; \n         private EditText nameEt;\n         private EditText capEt;\n         private EditText codeEt;\n         private TimePicker timeEt;\n         private TimePicker minEt;\n         private String cHour;\n         private String cMinute;\n         private String normalTimeFormat;\n\n           @Override\n           public void onCreate(Bundle savedInstanceState) \n           {\n              super.onCreate(savedInstanceState); \n              setContentView(R.layout.add_country);\n\n              nameEt = (EditText) findViewById(R.id.nameEdit);\n              capEt = (EditText) findViewById(R.id.capEdit);\n              codeEt = (EditText) findViewById(R.id.codeEdit);\n              timeEt = (TimePicker) findViewById(R.id.timeEdit);\n              minEt = (TimePicker) findViewById(R.id.timeEdit);\n\n\n\n              Bundle extras = getIntent().getExtras(); \n\n              if (extras != null)\n              {\n                 rowID = extras.getLong(\"row_id\");\n                 nameEt.setText(extras.getString(\"name\"));  \n                 capEt.setText(extras.getString(\"cap\"));  \n                 codeEt.setText(extras.getString(\"code\"));  \n                 timeEt.setCurrentHour(extras.getInt(\"time\"));\n                 minEt.setCurrentMinute(extras.getInt(\"min\"));\n              }\n\n              Button saveButton =(Button) findViewById(R.id.saveBtn);\n              saveButton.setOnClickListener(new OnClickListener() {\n\n                  public void onClick(View v) \n                  {\n                     if (nameEt.getText().length() != 0)\n                     {\n                        AsyncTask saveContactTask = \n                           new AsyncTask() \n                           {\n                              @Override\n                              protected Object doInBackground(Object... params) \n                              {\n                                 saveContact();\n                                 return null;\n                              }\n\n                              @Override\n                              protected void onPostExecute(Object result) \n                              {\n                                 finish();\n                              }\n                           }; \n\n                        saveContactTask.execute((Object[]) null); \n                     }\n\n                     else\n                     {\n                        AlertDialog.Builder alert = new AlertDialog.Builder(AddEditCountry.this);\n                        alert.setTitle(R.string.errorTitle); \n                        alert.setMessage(R.string.errorMessage);\n                        alert.setPositiveButton(R.string.errorButton, null); \n                        alert.show();\n                     }\n                  } \n             });\n           }\n\n\n               private void saveContact() \n               {\n                  DatabaseConnector dbConnector = new DatabaseConnector(this);\n\n                  if (getIntent().getExtras() == null)\n                  {\n                      dbConnector.insertContact(nameEt.getText().toString(),\n                              capEt.getText().toString(),\n                              timeEt.getCurrentHour().toString(),\n                              minEt.getCurrentMinute().toString(),\n                              codeEt.getText().toString());\n                  }\n                  else\n                  {\n                      dbConnector.updateContact(rowID,\n                              nameEt.getText().toString(),\n                              capEt.getText().toString(),\n\n\n                              String cHour = timeEt.getCurrentHour().toString(), \/* Storing as String*\/\n                              String cMinute = minEt.getCurrentMinute().toString(), \n                              String normalTimeFormat = cHour + \":\" + cMinute;\n\n                              \/\/Do whatever you want to do with normalTimeFormat\n\n                              codeEt.getText().toString());\n                        }\n               }\n    }\n\n\n\n\n**DATABASECONNECTOR JAVA**\n=========================\n\n     import android.content.ContentValues;\n     import android.content.Context;\n     import android.database.Cursor;\n     import android.database.SQLException;\n     import android.database.sqlite.SQLiteDatabase;\n\n       public class DatabaseConnector {\n\n    private static final String DB_NAME = \"WorldCountries\";\n    private SQLiteDatabase database;\n    private DatabaseOpenHelper dbOpenHelper;\n\n    public DatabaseConnector(Context context) {\n        dbOpenHelper = new DatabaseOpenHelper(context, DB_NAME, null, 1);\n    }\n\n       public void open() throws SQLException \n       {\n          \/\/open database in reading\/writing mode\n          database = dbOpenHelper.getWritableDatabase();\n       } \n\n       public void close() \n       {\n          if (database != null)\n             database.close();\n       }       \n\n       public void insertContact(String name, String cap, String code, String time, String min) \n               {\n                  ContentValues newCon = new ContentValues();\n                  newCon.put(\"name\", name);\n                  newCon.put(\"cap\", cap);\n                  newCon.put(\"time\", time);\n                  newCon.put(\"min\", min);\n                  newCon.put(\"code\", code);\n\n                  open();\n                  database.insert(\"country\", null, newCon);\n                  close();\n               }\n\n               public void updateContact(long id, String name, String cap,String code,  String time, String min) \n               {\n                  ContentValues editCon = new ContentValues();\n                  editCon.put(\"name\", name);\n                  editCon.put(\"cap\", cap);\n                  editCon.put(\"time\", time);\n                  editCon.put(\"min\", min);\n                  editCon.put(\"code\", code);\n\n                  open();\n                  database.update(\"country\", editCon, \"_id=\" + id, null);\n                  close();\n               }\n\n               public Cursor getAllContacts() \n               {\n                  return database.query(\"country\", new String[] {\"_id\", \"name\"}, \n                     null, null, null, null, \"name\");\n               }\n\n               public Cursor getOneContact(long id) \n               {\n                  return database.query(\"country\", null, \"_id=\" + id, null, null, null, null);\n               }\n\n               public void deleteContact(long id) \n               {\n                  open(); \n                  database.delete(\"country\", \"_id=\" + id, null);\n                  close();\n               }\n     }\n\n\n**DATABASEOPENHELPER JAVA**\n===============================\n    import android.content.Context;\n    import android.database.sqlite.SQLiteDatabase;\n    import android.database.sqlite.SQLiteDatabase.CursorFactory;\n    import android.database.sqlite.SQLiteOpenHelper;\n\n    public class DatabaseOpenHelper extends SQLiteOpenHelper {\n\n    public DatabaseOpenHelper(Context context, String name,\n            CursorFactory factory, int version) {\n        super(context, name, factory, version);\n    }\n\n    @Override\n    public void onCreate(SQLiteDatabase db) {\n        String createQuery = \"CREATE TABLE country (_id integer primary key autoincrement,name, cap, code,  time, min);\";                 \n        db.execSQL(createQuery);        \n    }\n\n    @Override\n    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {\n\n    }\n     }\n\n\n\n\n LOGCAT:\n==========\n\n\n\n    03-22 14:35:00.174: I\/Adreno200-EGLSUB(1320): : Format RGBA_8888.\n    03-22 14:35:00.174: D\/memalloc(1320): ion: Mapped buffer base:0x5ca41000 size:614400 offset:0 fd:57\n    03-22 14:35:00.184: E\/(1320): Can't open file for reading\n    03-22 14:35:00.184: E\/(1320): Can't open file for reading\n    03-22 14:35:00.225: D\/memalloc(1320): ion: Mapped buffer base:0x5d12e000 size:614400 offset:0 fd:61\n    03-22 14:35:02.087: D\/Activity(1320): Activity.onPause(), editTextTapSensorList size: 0\n    03-22 14:35:02.127: I\/Adreno200-EGLSUB(1320): : Format RGBA_8888.\n    03-22 14:35:02.127: D\/memalloc(1320): ion: Mapped buffer base:0x5d4ce000 size:614400 offset:0 fd:64\n    03-22 14:35:02.227: D\/memalloc(1320): ion: Mapped buffer base:0x5d6f7000 size:614400 offset:0 fd:71\n    03-22 14:35:02.247: D\/memalloc(1320): ion: Unmapping buffer  base:0x5ca41000 size:614400\n    03-22 14:35:02.247: D\/memalloc(1320): ion: Unmapping buffer  base:0x5d12e000 size:614400\n    03-22 14:35:02.917: D\/memalloc(1320): ion: Mapped buffer base:0x5c929000 size:614400 offset:0 fd:56\n    03-22 14:35:04.319: D\/Activity(1320): Activity.onPause(), editTextTapSensorList size: 0\n    03-22 14:35:04.509: I\/Adreno200-EGLSUB(1320): : Format RGBA_8888.\n    03-22 14:35:04.509: D\/memalloc(1320): ion: Mapped buffer base:0x5ca41000 size:614400 offset:0 fd:60\n    03-22 14:35:04.599: D\/memalloc(1320): ion: Mapped buffer base:0x5dc02000 size:614400 offset:0 fd:75\n    03-22 14:35:04.619: D\/memalloc(1320): ion: Mapped buffer base:0x5dca8000 size:614400 offset:0 fd:78\n    03-22 14:35:04.629: D\/memalloc(1320): ion: Unmapping buffer  base:0x5d4ce000 size:614400\n    03-22 14:35:04.629: D\/memalloc(1320): ion: Unmapping buffer  base:0x5d6f7000 size:614400\n    03-22 14:35:04.629: D\/memalloc(1320): ion: Unmapping buffer  base:0x5c929000 size:614400\n    03-22 14:35:08.433: W\/dalvikvm(1320): threadid=12: thread exiting with uncaught exception (group=0x410889d8)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320): FATAL EXCEPTION: AsyncTask #2\n    03-22 14:35:08.453: E\/AndroidRuntime(1320): java.lang.RuntimeException: An error occured while executing doInBackground()\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     at android.os.AsyncTask$3.done(AsyncTask.java:278)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     at java.lang.Thread.run(Thread.java:856)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320): Caused by: java.lang.Error: Unresolved compilation problems: \n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     String cannot be resolved to a variable\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     Syntax error on token \"cHour\", delete this token\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     String cannot be resolved to a variable\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     Syntax error on token \"cMinute\", delete this token\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     Syntax error, insert \")\" to complete MethodInvocation\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     Syntax error, insert \";\" to complete BlockStatements\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     String cannot be resolved to a variable\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     Syntax error on token \")\", delete this token\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     at com.nfc.linkingmanager.AddEditCountry.saveContact(AddEditCountry.java:122)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     at com.nfc.linkingmanager.AddEditCountry.access$1(AddEditCountry.java:103)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     at com.nfc.linkingmanager.AddEditCountry$1$1.doInBackground(AddEditCountry.java:76)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     at android.os.AsyncTask$2.call(AsyncTask.java:264)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)\n    03-22 14:35:08.453: E\/AndroidRuntime(1320):     ... 5 more\n    03-22 14:35:08.493: D\/Activity(1320): Activity.onPause(), editTextTapSensorList size: 0\n    03-22 14:35:08.563: I\/Adreno200-EGLSUB(1320): : Format RGBA_8888.\n    03-22 14:35:08.563: D\/memalloc(1320): ion: Mapped buffer base:0x5d4bb000 size:614400 offset:0 fd:56\n    03-22 14:35:08.573: D\/memalloc(1320): ion: Mapped buffer base:0x5d8f7000 size:614400 offset:0 fd:64\n    03-22 14:35:08.593: D\/memalloc(1320): ion: Unmapping buffer  base:0x5ca41000 size:614400\n    03-22 14:35:08.593: D\/memalloc(1320): ion: Unmapping buffer  base:0x5dc02000 size:614400\n    03-22 14:35:08.593: D\/memalloc(1320): ion: Unmapping buffer  base:0x5dca8000 size:614400\n    03-22 14:35:09.775: D\/memalloc(1320): ion: Mapped buffer base:0x5ca41000 size:614400 offset:0 fd:60\n\n\n\n\n\nAdditional Info:\n============\n\nIt only force closes after you click the save button in add_country:\n\nButton android:id=\"@+id\/saveBtn\n<\/code><\/pre>\n<ol>\n<li>\n<p>JodaTime has a LocalTime class that can be constructed with hours and minutes. It also have a toString method that is able to generate a string for a specified pattern.<\/p>\n<\/li>\n<li>\n<p><code>Your code has lot of compilation errors<\/code>, And one of them is<\/p>\n<p>Your Create table statement is wrong<\/p>\n<pre><code>String createQuery = \"CREATE TABLE country (_id integer primary key autoincrement,name, cap, code,  time, min);\";   \n<\/code><\/pre>\n<p>you have not specified the <code>type<\/code> of the other fields i.e <code>name,cap,code, time and min<\/code><\/p>\n<p>specify the type for them like this<\/p>\n<pre><code>String createQuery = \"CREATE TABLE country (_id integer primary key autoincrement,name text, cap text , code text ,  time text , min text );\";   \n<\/code><\/pre>\n<p><strong>second<\/strong> :<\/p>\n<pre><code>dbConnector.updateContact(rowID,\n                              nameEt.getText().toString(),\n                              capEt.getText().toString(),\n\n\n                              String cHour = timeEt.getCurrentHour().toString(), \/* Storing as String*\/\n                              String cMinute = minEt.getCurrentMinute().toString(), \n                              String normalTimeFormat = cHour + \":\" + cMinute;\n\n                              \/\/Do whatever you want to do with normalTimeFormat\n\n                              codeEt.getText().toString());\n<\/code><\/pre>\n<p><strong>this is not the way to call method<\/strong>. You can&#8217;t create a new string inside the method parameter. it should be like this<\/p>\n<pre><code> dbConnector.updateContact(rowID, nameEt.getText().toString(),capEt.getText().toString(),timeEt.getCurrentHour().toString()+\":\"+minEt.getCurrentMinute().toString(), codeEt.getText().toString());\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-02-03 02:35:16. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have an application which stores the CurrentHour and CurrentMinute from a TimePicker in a sqlite database then displays it in another activity ViewCountry java I would like to combine these two fields in and display them together 9:30 &#8211; for example in the of view_country xml add_country xml ================= **ADDEDITCOUNTRY** ============================ quite possible minute [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2575","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2575"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2575\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}