2013-03-08 46 views
0

enter image description here 只有2個在我的應用程序調用振動Android的運行時錯誤振動

1. Vibration Call 

listView.setOnItemClickListener(new OnItemClickListener() { 
    public void onItemClick(AdapterView<?> parent, final View view, 
         int position, long id) { 
... 
    vibrator.vibrate(200); 
...} 
} 

2. Vibration Call  

public void onSensorChanged(SensorEvent event) { 
      if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { 
    } 
    .... 
//z axes accelerator changes 
    long[] pattern = { 0, 200, 200 }; 
        vibrator.vibrate(pattern, 3); 
    }} 

我覺得第一個是coasing錯誤。

我真的沒有看到任何錯誤。

它是我第一次編程振動。

我該如何解決這個問題?

回答

0

我認爲這會工作

long[] pattern = new long[]{ 0, 200, 200 }; 
        vibrator.vibrate(pattern, 3); 
+0

vibrator.vibrate(模式,3);意味着重複模式3x – nkvnkv 2013-03-08 12:06:55

+0

@nkvnkv編輯我的答案我想你忘了初始化數組 – DjHacktorReborn 2013-03-08 12:48:38

0

目前最好的解決辦法是

Handler handler = new Handler(); 
handler.post(new Runnable() { 
     public void run() { 
vibrator.vibrate(200); 
     } 

}); 
} 

應用程序不會崩潰,但振動有時會失敗