Android 手电筒应用程序例外:“;无法连接到摄像头服务“;

Android 手电筒应用程序例外:“;无法连接到摄像头服务“;,android,camera,flashlight,Android,Camera,Flashlight,我是Android应用程序开发新手,我曾试图构建一个基本的手电筒应用程序,但似乎大多数库都不推荐使用。我试过做Camera.Parameters-Camera但仍不工作。日志显示异常:由以下原因引起:java.lang.RuntimeException:无法连接到摄像头服务AndroidManifest.xml <uses-permission android:name="android.permission.CAMERA"/> <uses-feature android:na

我是Android应用程序开发新手,我曾试图构建一个基本的手电筒应用程序,但似乎大多数库都不推荐使用。我试过做
Camera.Parameters-Camera但仍不工作。日志显示异常:
由以下原因引起:java.lang.RuntimeException:无法连接到摄像头服务


AndroidManifest.xml

<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus"/>

活动\u main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.thenewboston.flashlight.MainActivity"
android:background="#000000">


<ImageButton
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:id="@+id/imageButton"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/mytoggle"
    android:scaleType="fitCenter"
    android:background="@null"
    android:onClick="myButton" />
</RelativeLayout>


我知道,我在我的代码中使用了过时的东西,但这可能是因为我还没有看到有人为
棉花糖
开发手电筒应用程序。如果有人能建议新的代码,这将是有益的或正确的我的代码(上面给出)将不胜感激

此问题可能更适合于。@IanP此问题要求帮助解决错误。它不适合于代码检查。此问题可能更适合于。@IanP此问题要求帮助解决错误。它不适合代码审查。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.thenewboston.flashlight.MainActivity"
android:background="#000000">


<ImageButton
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:id="@+id/imageButton"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/mytoggle"
    android:scaleType="fitCenter"
    android:background="@null"
    android:onClick="myButton" />
</RelativeLayout>