안녕하세요. 내 서버에서 배열을 가져 오는 중 문제가 발생했습니다. 나는 가능한 한 구체적으로하려고 노력할 것입니다. 나는이 포스트가 너무 길지 않을 것을 바란다.어레이 유형에서 setText (String)을 호출 할 수 없습니다.
public static Appointment[] getAppointments(DateTime date, String titel, String note, Date startDate, Date endDate, String location) {
Gson gson = new GsonBuilder().create();
Appointment[] appointments = new Appointment[1];
CalendarDate calendarDate;
appointments.setTitle(titel);
appointments.setNote(note);
appointments.setStartDate(startDate);
appointments.setEndDate(endDate);
appointments.setLocation(location);
String gsonString = gson.toJson(date);
String result = GetCalendar(gsonString);
appointments = (Appointment[])gson.fromJson(result, Appointment[].class);
return appointments;
}
private static String GetCalendar(String jsonInput){
String result = "Error";
try {
Socket clientSocket = new Socket("localhost", 8888);
DataOutputStream outToServer = new DataOutputStream(
clientSocket.getOutputStream());
byte[] input = jsonInput.getBytes();
byte key = (byte) 3.1470;
byte[] encrypted = input;
for (int i = 0; i < encrypted.length; i++)
encrypted[i] = (byte) (encrypted[i]^key);
System.out.println(encrypted);
outToServer.write(encrypted);
outToServer.flush();
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(
clientSocket.getInputStream()));
result = inFromServer.readLine();
clientSocket.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
서버 프로젝트에있는이 클래스에서 데이터를 수신합니다.
public class Events {
ArrayList<Calendar> events = new ArrayList<Calendar>();
public ArrayList<Calendar> getEvents() {
QueryBuilder qb = new QueryBuilder();
try {
ResultSet rs = qb.selectFrom("calendar").all().ExecuteQuery();
while (rs.next())
{
//String values from SQL database (must be created)
int calendarID = rs.getInt("Calendarid");
int createdby = rs.getInt("userid");
Date startDate = rs.getDate("start");
Date endDate = rs.getTime("end");
String title = rs.getString("Title");
String note = rs.getString("Note");
String location = rs.getString("Location");
int stringCalendarID = Integer.valueOf(calendarID);
int stringCreatedby = Integer.valueOf(createdby);
String stringTitle = String.valueOf(title);
String stringNote = String.valueOf(note);
String stringLocation = String.valueOf(location);
//System.out.println(String.valueOf(startDate.getTime()));
events.add(new Calendar(stringCalendarID, stringCreatedby, stringTitle, stringNote, stringLocation));
}
} catch (SQLException e) {
e.printStackTrace();
}
return events;
}
public void setEvents(ArrayList<Calendar> calendar) {
this.events = calendar;
}
그러나 나는 모든 약속
에서이 오류가
appointments.setTitle(titel);
appointments.setNote(note);
appointments.setStartDate(startDate);
appointments.setEndDate(endDate);
appointments.setLocation(location);
배열 타입의 약속 [] 내가 뭘 잘못
에 setTitle이라는 (String)를 호출 할 수 있습니까? 도와 드리겠습니다.