0
我试图从用户中捕获任何触摸事件以在布尔验证中使用它(如“press on屏幕继续“)。但我得到一个错误,这是问题的标题。 它说行:尝试调用空对象的虚拟方法'int android.view.MotionEvent.getAction()'参考
resultadoPalavra.setText("Você acertou! Pressione na tela para continuar");
是,“按屏幕上继续”我曾提到过。
代码:
public class ApurarResultadoFragment extends Fragment{
private TextView resultadoPalavra;
String palavraDigitada;
String resposta;
MainActivity mActivity = new MainActivity();
private boolean isTouch = false;
MotionEvent event;
public ApurarResultadoFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_apurar_resultado, container, false);
resultadoPalavra = (TextView) view.findViewById(R.id.TextViewTesteFragment);
palavraDigitada = this.getArguments().getString("oqSeraFalado");
resposta = this.getArguments().getString("resposta");
if(testeResultado()){
resultadoPalavra.setText("Você acertou! Pressione na tela para continuar");
if(onTouchEvent(view, event)){
Log.v("teste","" + isTouch);
}
}
return view;
}
public boolean onTouchEvent(View v, MotionEvent event){
int eventaction = event.getAction();
switch (eventaction){
case MotionEvent.ACTION_DOWN:
isTouch = true;
break;
case MotionEvent.ACTION_UP:
isTouch = true;
break;
case MotionEvent.ACTION_MOVE:
isTouch = true;
break;
}
return true;
}
public boolean testeResultado() {
if (resposta.equalsIgnoreCase(palavraDigitada)){
return true;
}else{
return false;
}
}
}
我怎么能初始化变量 “事件”?我猜她是问题
的可能的复制[什么是一个NullPointerException,以及如何解决它?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) –