Android app encoding problem - not display ÅÄÖ properly
When user enters a value 'Nedskräpning' in a EditTextbox, it is saved as 'Nedskräpning' in the database. So I am assuming this error is generated from the Android part of the application. UPDATE: <-- probably false assumption?
<EditText android:id="@+id/commentTextBox"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1"/>
The java code:
commentTextBox = (EditText) findViewById(R.id.commentTextBox);
crapport.setComment(commentTextBox.getText().toString());
Then this crapport is saved in the database.
Any tips on how to solve this?
UPDATE: This is my Apache CXF webservice:
@Path("/crapportService/")
public class CrapportServiceImpl implements CrapportService {
@Autowired
private CrapportController crapportController;
@Override
@Path("image")
@POST
@Produces(MediaType.TEXT_HTML)
public String addReport(MultipartBody multipartBody) {
List<Attachment> attachmentList = new ArrayList<Attachment>();
attachmentList = multipartBody.getAllAttachments();
if (attachmentList.size() == 0){
return "No attachments"开发者_JAVA百科;
}
try {
crapportController.processReportFromClient(attachmentList);
} catch (FileNotFoundException e) {
e.printStackTrace();
return "Error: FileNotFoundException";
} catch (NullPointerException e) {
return "Error: NullPointerException";
} catch (IOException e) {
return "Error: IOException";
}
return "Success";
}
}
I looks to me your database uses ISO-8859-15 or ISO-8859-1 as encoding, the string from Android is in UTF-8 and if stored into the database the high word and the low word from the UTF-8 "Ä" get split into their two ISO-8859-1 counterparts, making it "ä".
Solved it by passing a character encoding argument to the string-creation. eg) new String("values", Charset.forName("UTF-8")) in the controller part of the backend-application.
精彩评论