如何解决手势导致错误(由java.lang.NullpointerException引起)?
public class GusterActivity extends Activity implements OnGesturePerformedListener
{
TextView txtmsg;
TextView txtwrt;
private GestureLibrary gesturelib;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GestureOverlayView gestureoverlayview=new GestureOverlayView(this);
View inflate=getLayoutInflater().inflate(R.layout.main,null);
gestureoverlayview.addView(inflate);
gestureoverlayview.addOnGesturePerformedListener(this);
gesturelib= GestureLibraries.fromRawResource(this,R.raw.gestures);
if(gesturelib.load()){
finish();
}
setContentView(gestureoverlayview);
}
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
ArrayList<Prediction> predictions = gesturelib.recognize(gesture);
for(Prediction prediction : predictions){
if(prediction.score>1.0){
Toast.makeText(this,prediction.name,Toast.LENGTH_SHORT);
}
}
}
public class GusterActivity extends Activity implements OnGesturePerformedListener
{
TextView txtmsg;
TextView txtwrt;
private GestureLibrary gesturelib;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GestureOverlayView gestureoverlayview=new GestureOverlayView(this);
View inflate=getLayoutInflater().inflate(R.layout.main,null);
gestureoverlayview.addView(inflate);
gestureoverlayview.addOnGesturePerformedListener(this);
gesturelib= GestureLibraries.fromRawResource(this,R.raw.gestures);
if(gesturelib.load()){
finish();
}
setContentView(gestureoverlayview);
}
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
ArrayList<Prediction> predictions = gesturelib.recognize(gesture);
for(Prediction prediction : predictions){
if(prediction.score>1.0){
Toast.makeText(this,prediction.name,Toast.LENGTH_SHORT);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能你得到的是空指针,因为你的gesturelib在行中为空(gesturelib= GestureLibraries.fromRawResource(this,R.raw.gestures);)
May be you are getting nullpointer because your gesturelib is null in line( gesturelib= GestureLibraries.fromRawResource(this,R.raw.gestures);)