{"id":2566,"date":"2022-08-30T15:25:56","date_gmt":"2022-08-30T15:25:56","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/03\/the-method-settextstring-is-undefined-for-timepicker-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:25:56","modified_gmt":"2022-08-30T15:25:56","slug":"the-method-settextstring-is-undefined-for-timepicker-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/the-method-settextstring-is-undefined-for-timepicker-collection-of-common-programming-errors\/","title":{"rendered":"The method setText(String) is undefined for TimePicker-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m getting 3 errors with the following source &#8211; can anyone explain what I&#8217;m doing wrong?<\/p>\n<p>The errors &#8211;<\/p>\n<p>minEdit cannot be resolved or is not a field The method setText(String) is undefined for TimePicker The method setText(String) is undefined for TimePicker<\/p>\n<p>P.S.<\/p>\n<p>The second two are occuring at the following line:<\/p>\n<pre><code>         timeEt.setText(extras.getString(\"time\"));\n         minEt.setText(extras.getString(\"min\"));\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\n\n\n      \n   \n\n<\/code><\/pre>\n<p>JAVA:<\/p>\n<pre><code>import android.app.Activity;\nimport android.app.AlertDialog;\nimport android.os.AsyncTask;\nimport android.os.Bundle;\nimport android.view.ViewGroup;\nimport android.view.View;\nimport android.view.View.OnClickListener;\nimport android.widget.Button;\nimport android.widget.EditText;\nimport android.widget.FrameLayout;\nimport android.widget.TimePicker;\n\npublic 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\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.minEdit);\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.setText(extras.getString(\"time\"));\n             minEt.setText(extras.getString(\"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                    timeEt.getCurrentHour().toString(),\n                    minEt.getCurrentMinute().toString(),\/* Storing as String*\/\n                    codeEt.getText().toString());\n              }\n           }\n}\n<\/code><\/pre>\n<ol>\n<li>\n<p><em>The method setText(String) is undefined for TimePicker<\/em><\/p>\n<p><code>TimePicker<\/code> does not have a setText() method, you have to use <code>setCurrentHour(Integer)<\/code> and <code>setCurrentMinute(Integer)<\/code> to change the values.<\/p>\n<p><em>minEdit cannot be resolved or is not a field<\/em><\/p>\n<p>means you are trying to access are variable with the name <code>minEdit<\/code> but you haven&#8217;t declared it anywhere. Probably you&#8217;ve made a typo where you declared it. I actually could not find any minEdit field at your code, so I can not guess where the error really comes from.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-02-03 02:34:28. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m getting 3 errors with the following source &#8211; can anyone explain what I&#8217;m doing wrong? The errors &#8211; minEdit cannot be resolved or is not a field The method setText(String) is undefined for TimePicker The method setText(String) is undefined for TimePicker P.S. The second two are occuring at the following line: timeEt.setText(extras.getString(&#8220;time&#8221;)); minEt.setText(extras.getString(&#8220;min&#8221;)); JAVA: [&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-2566","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2566","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=2566"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2566\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}