Java 安卓绑定&;MVVM:未报告的异常;必须抓住
我试图学习数据绑定和MVVM模式,但我遇到了一个异常问题 我的viewmodel有一个例外:Java 安卓绑定&;MVVM:未报告的异常;必须抓住,java,android,exception,binding,Java,Android,Exception,Binding,我试图学习数据绑定和MVVM模式,但我遇到了一个异常问题 我的viewmodel有一个例外: public void play(String move) throws Exception, ChessMoveException{ String[] positions = move.split("\\s+"); try { Position position1 = new Position(positions[0]); Position po
public void play(String move) throws Exception, ChessMoveException{
String[] positions = move.split("\\s+");
try {
Position position1 = new Position(positions[0]);
Position position2 = new Position(positions[1]);
this.model.turn(position1, position2);
if(this.model.getCurrentColor().equals(Color.WHITE)) {
this.model.setCurrentColor(Color.BLACK);
messageTurn.set(R.string.blackTurn);
} else {
this.model.setCurrentColor(Color.WHITE);
messageTurn.set(R.string.whiteTurn);
}
} catch (Exception ex) {
//TODO : Toast Exception
}
}
我在MainActivityEventHandlers中使用此方法播放:
public void onButtonPlayClicked(View v) throws Exception {
Log.i("MESSAGE", "Play");
try {
this.activity.binding.getViewModel().play(this.activity.binding.editTurn.getText().toString());
} catch (Exception ex) {
Log.i("EXCEPTION", "");
}
}
在我的activity_main.xml中,我使用了onClick属性:android:onClick=“@{eventHandlers.onButtonPlayClicked}”
但当我尝试启动代码时,出现以下错误:
错误:(374,43)错误:未报告的异常;必须捕获或声明要抛出
当我单击它时,它会在生成的ActivityMainBinding.java类上重定向我,因此我无法编辑它以在onClick方法上添加我的异常:
public void onClick(android.view.View arg0) {
this.value.onButtonPlayClicked(arg0);
}
要修复此错误,需要做些什么吗?
谢谢你的方法
public void onButtonPlayClicked(View v) throws Exception {
Log.i("MESSAGE", "Play");
try {
this.activity.binding.getViewModel().play(this.activity.binding.editTurn.getText().toString());
} catch (Exception ex) {
Log.i("EXCEPTION", "");
}
}
声明它可以抛出异常,但也可以捕获所有异常。我想这在某种程度上混淆了数据绑定插件生成绑定类的过程