2012-12-05 60 views
1

* *我想改變在聯繫人API的圖片,但我得到了一些例外,請檢查我的代碼如何更改谷歌應用程序聯繫人API中的圖片?

String filepath="C:\\Users\\bhanuprasad\\Documents\\Downloads\\549002_459129587462191_1689883124_n.jpg"; 
    File file = new File(filepath); 

    byte[] photoData = new byte[(int) file.length()]; 
String url="https://www.google.com/m8/feeds/profiles/domain/"+ sDomain + "/full/[email protected]" ; 
    ContactEntry profile = contactService.getEntry(
      new URL(url),ContactEntry.class); 
GDataRequest request = contactService.createRequest(GDataRequest.RequestType.UPDATE, 
      photoUrl, new ContentType("image/jpeg")); 

     request.setEtag(photoLink.getEtag()); 
    OutputStream requestStream = request.getRequestStream(); 
     requestStream.write(photoData); 
    request.execute(); 

當我打電話request.execute();我得到以下異常

com.google.gdata.util.InvalidEntryException:壞請求 無效的圖像文件

at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:594) 
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563) 
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552) 
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530) 
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535) 

請幫我....

+0

任何人都請幫助我...我從4小時開始在這裏... .... – user1686253

回答

0

我看不出有任何代碼實際上讀取您的圖像。您只使用文件的長度初始化字節數組。據推測,未初始化的文件不是有效的圖像。獲取實際的照片數據到您的字節數組,它應該工作。