如何解决手势导致错误(由java.lang.NullpointerException引起)?

发布于 2024-12-31 23:14:37 字数 1079 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凹づ凸ル 2025-01-07 23:14:37

可能你得到的是空指针,因为你的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);)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文