The method setText(String) is undefined for TimePicker-Collection of common programming errors

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"));




    


   

      

      

    

    

    

        

        
    

    

    

    

        

        
    

    

    

    



    




      
   

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 saveContactTask = 
                       new AsyncTask() 
                       {
                          @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());
              }
           }
}
  1. The method setText(String) is undefined for TimePicker

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

    minEdit cannot be resolved or is not a field

    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.