50478

The method setText(String) is undefined for TimePicker

Question:

I'm getting 3 errors with the following source - can anyone explain what I'm doing wrong?

The errors -

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("time")); minEt.setText(extras.getString("min")); <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"> <LinearLayout android:id="@+id/linearLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="5dp"> <EditText android:id="@+id/nameEdit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:imeOptions="actionNext" android:hint="@string/name_hint" android:inputType="textPersonName|textCapWords"/> <EditText android:id="@+id/capEdit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:imeOptions="actionNext" android:hint="@string/cap_hint" android:inputType="textPersonName|textCapWords"/> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Data Limit" android:textColor="#ffffff" android:textAppearance="?android:textAppearanceMedium" /> <SeekBar android:id="@+id/seekBar1" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1.0" android:gravity="left" android:textColor="#ffffff" android:text="10MB" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1.0" android:gravity="right" android:textColor="#ffffff" android:text="Unlimited Data" /> </LinearLayout> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bandwidth Limit" android:textColor="#ffffff" android:textAppearance="?android:textAppearanceMedium" /> <SeekBar android:id="@+id/seekBar1" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1.0" android:gravity="left" android:textColor="#ffffff" android:text="10kbs" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1.0" android:textColor="#ffffff" android:gravity="right" android:text="Unlimited Bandwidth" /> </LinearLayout> <TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:textAppearanceSmall" /> <TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="WiFi Time Limit" android:textColor="#ffffff" android:textAppearance="?android:textAppearanceMedium" /> <TimePicker android:id="@+id/timeEdit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:layout_weight="1.0" /> <EditText android:id="@+id/codeEdit" android:inputType="textUri" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" android:lines="1" android:hint="@string/code_hint" android:imeOptions="actionNext" /> <Button android:id="@+id/saveBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:layout_gravity="center_horizontal" android:text="@string/save_btn"/> </LinearLayout> </ScrollView>

JAVA:

import android.app.Activity; import android.app.AlertDialog; import android.os.AsyncTask; import android.os.Bundle; import android.view.ViewGroup; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.TimePicker; public class AddEditCountry extends Activity { private long rowID; private EditText nameEt; private EditText capEt; private EditText codeEt; private TimePicker timeEt; private TimePicker minEt; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_country); nameEt = (EditText) findViewById(R.id.nameEdit); capEt = (EditText) findViewById(R.id.capEdit); codeEt = (EditText) findViewById(R.id.codeEdit); timeEt = (TimePicker) findViewById(R.id.timeEdit); minEt = (TimePicker) findViewById(R.id.minEdit); Bundle extras = getIntent().getExtras(); if (extras != null) { rowID = extras.getLong("row_id"); nameEt.setText(extras.getString("name")); capEt.setText(extras.getString("cap")); codeEt.setText(extras.getString("code")); timeEt.setText(extras.getString("time")); minEt.setText(extras.getString("min")); } Button saveButton =(Button) findViewById(R.id.saveBtn); saveButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (nameEt.getText().length() != 0) { AsyncTask<Object, Object, Object> saveContactTask = new AsyncTask<Object, Object, Object>() { @Override protected Object doInBackground(Object... params) { saveContact(); return null; } @Override protected void onPostExecute(Object result) { finish(); } }; saveContactTask.execute((Object[]) null); } else { AlertDialog.Builder alert = new AlertDialog.Builder(AddEditCountry.this); alert.setTitle(R.string.errorTitle); alert.setMessage(R.string.errorMessage); alert.setPositiveButton(R.string.errorButton, null); alert.show(); } } }); } private void saveContact() { DatabaseConnector dbConnector = new DatabaseConnector(this); if (getIntent().getExtras() == null) { dbConnector.insertContact(nameEt.getText().toString(), capEt.getText().toString(), timeEt.getCurrentHour().toString(), minEt.getCurrentMinute().toString(), codeEt.getText().toString()); } else { dbConnector.updateContact(rowID, nameEt.getText().toString(), capEt.getText().toString(), timeEt.getCurrentHour().toString(), minEt.getCurrentMinute().toString(),/* Storing as String*/ codeEt.getText().toString()); } } }

Answer1:

<em>The method setText(String) is undefined for TimePicker</em>

TimePicker does not have a setText() method, you have to use setCurrentHour(Integer) and setCurrentMinute(Integer) to change the values.

<em>minEdit cannot be resolved or is not a field</em>

means you are trying to access are variable with the name minEdit but you haven't declared it anywhere. Probably you'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.

Recommend

  • The method setText(String) is undefined for TimePicker
  • Android Custom Control Layout Troubles
  • Android Studio - can't run project - Error retrieving parent for item
  • How to make every content of a Relative Layout clickable in android
  • android popup layout over the whole screen
  • Button in header when implementing StickyGridHeaders Android
  • Can we use CSS in Android forms for android components?
  • Text overlapping in Android text view
  • Drop down seekbar in Android actionbar?
  • RuntimeException when input exceeds counterMaxLength of TextInputLayout
  • How can I enclose some XML elements in a bounding box?
  • how to get image from drawable according to their names in the sqlite database and then display it i
  • TextViews text change in a for loop
  • Android: Stop EditText from going outside of tablerow
  • ImageView not displaying correctly in the device
  • java.lang.IllegalArgumentException: This component requires that you specify a valid android:textApp
  • Bottom Navigation Bar: Text size is increasing on pressing?
  • How to link text in a TextView to open web URL
  • SeekBar - Showing progress with TextView above
  • How can I delay onClick action
  • android listpopupwindow list item textview not being multiline
  • How to change the font of tabLayout with a custom font / calligraphy
  • using viewHolder Interface to update state to Listview
  • Performance issue for Rails: How to send gzip assets
  • Android EditText - Stop cursor blinking, want a solid cursor
  • How do I use Java generic wildcards with methods taking more than one generic parameter?
  • Fancy dynamic list in Android: TableLayout vs ListView
  • Why does .addView throw this parent/child exception?
  • How to Handle Click on Imageview in Custom Listview with image and Textview?
  • Null ImageView Reference
  • Validaiting emails with Net.Mail MailAddress
  • MySQL WHERE-condition in procedure ignored
  • Web-crawler for facebook in python
  • Cannot Parse HTML Data Using Android / JSOUP
  • trying to dynamically update Highchart column chart but series undefined
  • embed rChart in Markdown
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal