Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代码跑不起来 不知道什么原因,希望能解惑 #4

Closed
guuguo opened this issue May 15, 2017 · 12 comments
Closed

代码跑不起来 不知道什么原因,希望能解惑 #4

guuguo opened this issue May 15, 2017 · 12 comments

Comments

@guuguo
Copy link

guuguo commented May 15, 2017

报错信息:

Error:Failed to complete Gradle execution.

Cause:
String index out of range: -1

gradle 控制台错误信息:

e: 错误: Exception while handling step android.databinding.annotationprocessor.ProcessExpressions@1e87f01c javax.xml.bind.UnmarshalException
e: 

e:    - with linked exception:
e:   [com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 3 无效。]
@guuguo guuguo changed the title 代码跑步起来 不知道什么原因 代码跑不起来 不知道什么原因,希望能解惑 May 15, 2017
@blackbbc
Copy link
Owner

在Databinding中,我使用了类似这样的绑定:
(取自activity_search.xml)

<TextView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text='@{"共:" + viewModel.totalCount + "个相关结果"}'
    android:textColor="@color/secondary_text"
    android:textSize="12sp"
    android:visibility="@{viewModel.totalCountVisibility}"
    tools:text="共:274个相关结果" />

注意到android:text这一行,我使用了中文。这在Unix系统下是可以编译通过的,然而在Windows下是无法编译通过的,详见:http://blog.csdn.net/yangheng362/article/details/70186866

@guuguo
Copy link
Author

guuguo commented May 16, 2017

谢谢,已经成功跑起来了,希望作者能把中文改成@string方式,方便我们windows用户

@StephenGiant
Copy link

我试了下 所有的硬编码写法都不行,只能@string

@WinDerek
Copy link

这算是Windows下开发Android使用DataBinding的常见问题了吧。因为Windows默认使用ANSI编码,简体中文的Windows下即GBK,所以需要加一个环境变量JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8来指定Javac默认的编码。
关于JAVA_TOOL_OPTIONS环境变量
所以不需要全用@string这种方式来替代硬编码,Windows用户一样可以开心地玩耍DataBinding!
@guuguo @blackbbc @StephenGiant

@StephenGiant
Copy link

我试过了你的环境变量方式 现在报的是另一个错 我还是把中文替换成string了 毕竟博主用到中文混搭接口数据的地方没几个 改起来也不是很大工作量
@DerekDick

@weiweiForAndroid
Copy link

@DerekDick 怎么配置这个环境变量呢?

@weiweiForAndroid
Copy link

@StephenGiant 知道怎么配置环境变量么?

@WinDerek
Copy link

@weiweiForAndroid 配置环境变量的方法是通用的,这个百度一下吧

@weiweiForAndroid
Copy link

@DerekDick 配置好了,运行的时候提示 Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

@WinDerek
Copy link

@weiweiForAndroid 这说明你环境变量配置成功了,忽略就行了

@weiweiForAndroid
Copy link

@DerekDick 好的 ,多谢。

@Everglowzz
Copy link

JAVA_TOOL_OPTIONS

环境变量 俩个= 啥意思

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants