Android:Vibrator不工作。 Foce关闭模拟器 [英] Android: Vibrator doesn't work. Foce Close emulator

查看:423
本文介绍了Android:Vibrator不工作。 Foce关闭模拟器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hey伙计,我还是一个Android& Java noob,但我看到的一切告诉我这应该完全工作,但它不是!不是在模拟器,不是在手机上..我想使用振动器使用vibrate(500); ..我收到应用程序意外停止错误

hey Guys, I'm still an Android & Java noob, but everything I've seen is telling me this should totally work, but it doesn't! not in the emulator, not on the phone.. I'm trying to use the vibrator using vibrate(500); ..I get an " application stopped unexpectedly " error

我缺少什么?

/ p>

code below:

package com.phys;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class phys extends Activity {

 Vibrator vibr;
 Button but;
 TextView txt;
 int counter = 0;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        vibr = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
        but = (Button)findViewById(R.id.Button01);
        txt = (TextView)findViewById(R.id.txt);
        but.setOnClickListener(clk);
    }

    OnClickListener clk = new OnClickListener(){

  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
   txt.setText(Integer.toString(counter));
   //do something else
   vibr.vibrate(500);
   counter++;
  }

    };
}


推荐答案

使用 adb logcat ,DDMS或Eclipse中的DDMS透视图来查看LogCat并检查与应用程序意外停止应用程序关联的堆栈跟踪。

Use adb logcat, DDMS, or the DDMS perspective in Eclipse to look at LogCat and examine the stack trace associated with your " application stopped unexpectedly " error. That will give you more information about where you are going wrong.

我怀疑问题是您缺少 VIBRATE 权限。如果是,请将其添加为 AndroidManifest.xml 文件中< manifest> p>

I suspect the problem is that you are missing the VIBRATE permission. If so, add this as a child of your <manifest> element in your AndroidManifest.xml file:

<uses-permission android:name="android.permission.VIBRATE"/>

这篇关于Android:Vibrator不工作。 Foce关闭模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆