LoginSignup
3
1

More than 5 years have passed since last update.

Windows環境でAndroidのDataBindingを使ってる時にMalformedByteSequenceExceptionが出た時の対処方法

Posted at

Windows環境でAndroidのDataBindingを使ってると以下のようなエラーが出ることがある。

Error:com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 3バイトのUTF-8シーケンスのバイト3が無効です

これはレイアウトXMLで直接日本語を使ってるいると起きる。
例えばこんな感じの記述

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>
        <variable
            name="hogeFlag"
            type="Boolean"/>
    </data>

....

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        text="@{hogeFlag ? `だめな日本語` : `foo`}"/>

</layout>

こういう時は素直にstringリソースを使うようにすれば正しく動く

<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        text="@{hogeFlag ? @string/hoge : @string/foo}"/>

一時的なものとして入れてたら思わぬ問題が起きてしまった。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1