-1
我正試圖發送數據到firebase。方法無法解析
我想在一個方法中調用時間和日期,並且該方法負責將數據發送到消防基地。
當我嘗試打電話時間和日期它給了我這個錯誤。
getText.toString method cannot resolved
在這條線:
myRef.setValue(ft1.getText().toString());
和.getText
其他用途。
我的代碼:
public class Room1 extends AppCompatActivity {
boolean hasSetTime = false;
boolean hasSetDate = false;
boolean hasSetTime1 = false;
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.room1);
final Calendar c = Calendar.getInstance();
final int year = c.get(Calendar.YEAR);
final int month = c.get(Calendar.MONTH);
final int day = c.get(Calendar.DAY_OF_MONTH);
final int hour = c.get(Calendar.HOUR_OF_DAY);
final int minute1 = c.get(Calendar.MINUTE);
final Calendar v = Calendar.getInstance();
final int hour2 = v.get(Calendar.HOUR_OF_DAY);
final int minute2 = v.get(Calendar.MINUTE);
final String date;
final EditText ft1;
final EditText fd1;
final EditText e1;
ft1 = (EditText) findViewById(R.id.ft1);
fd1 = (EditText) findViewById(R.id.fd1);
e1 = (EditText) findViewById(R.id.e1);
fd1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DatePickerDialog datepick = new DatePickerDialog(Room1.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
fd1.setText(dayOfMonth + "/" + month + "/" + year);
SimpleDateFormat dateFormatter;
Date d;
String entered_dob;
d = new Date(year, month, day);
dateFormatter = new SimpleDateFormat("MM-dd-yyyy");
entered_dob = dateFormatter.format(fd1.getText());
hasSetDate = true;
sendDataToFireBase();
}
},
year, month, day);
datepick.setTitle("select date");
datepick.show();
}
});
e1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TimePickerDialog timepickend = new TimePickerDialog(Room1.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
e1.setText(hourOfDay + ":" + minute);
hasSetTime = true;
sendDataToFireBase();
}
}, hour2, minute2, true
);
timepickend.setTitle("select time");
timepickend.show();
}
});
ft1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TimePickerDialog timepick = new TimePickerDialog(Room1.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay2, int minute2) {
ft1.setText(hourOfDay2 + ":" + minute2);
hasSetTime1=true;
sendDataToFireBase();
}
}, hour, minute1, true
);
timepick.setTitle("select time");
timepick.show();
}
}
);
}
public void sendDataToFireBase() {
if (hasSetTime == true && hasSetDate==true&&hasSetTime1==true) {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("Date");
myRef.setValue(ft1.getText().toString());
DatabaseReference myRef2 = database.getReference("Time");
myRef2.setValue(e1.getText().toString());
DatabaseReference myRef3 = database.getReference("Timereserved");
myRef2.setValue(fd1.getText().toString());
}
}
}
哪條線路會導致錯誤? –
我把錯誤小時前,當我試圖修復它 –
@代碼學徒的方法sendDataToFireBase() –