2014-12-03 2 views
0

안녕하세요. 내 서버에서 배열을 가져 오는 중 문제가 발생했습니다. 나는 가능한 한 구체적으로하려고 노력할 것입니다. 나는이 포스트가 너무 길지 않을 것을 바란다.어레이 유형에서 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)를 호출 할 수 있습니까? 도와 드리겠습니다.

답변

0

약속은 [] 완전히 새로운 개체 유형을 만듭니다. 이제는 더 이상 예약 객체가 아니므로 setTitle 멤버를 상속받지 않습니다.

당신은 배열에서 약속 개체를 얻을 다음에 setTitle이라는 함수를 호출 할 수 있습니다 : 예를 들어

Appointment a = appointments[who]; 
a.setTitle("whatever"); 

또는 더 간단하게

(appointments[who]).setTitle("whatever"); 

"" 두 예제의 약속 배열에있는 항목의 인덱스를 나타내는 정수입니다.

0

배열에 setTitle 메서드가 없으므로, Appointment을 사용합니다 (가정).

은 아마 당신은 같은 뭔가를 찾고있다 : 약속 객체의 배열 :

Appointment appointment = new Appointment(); 
appointment.setTitle(titlel); 
//etc. 
Appointment[] appointments = new Appointment[1]; 
appointments[0] = appointment; 
관련 문제