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

时间:2012-01-31 09:53:44

标签: android nullpointerexception gesture

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);



        }
    }
}

1 个答案:

答案 0 :(得分:0)

可能是因为你的gesturelib在行中是null,所以你得到了nullpointer(gesturelib = GestureLibraries.fromRawResource(this,R.raw.gestures);)