Java Android应用程序返回NULL

Java Android应用程序返回NULL,java,android,xml,button,android-audiomanager,Java,Android,Xml,Button,Android Audiomanager,在开始之前,让我说我已经搜索了过去两天来解决错误,确实找到了一些有用的解决方案,但对我来说不起作用。最后,我在这里发布我的代码: 关于守则: 我想编写一个Java应用程序来检查将音频管理器设置为MODE_IN_CALL的场景 代码: 和xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" packa

在开始之前,让我说我已经搜索了过去两天来解决错误,确实找到了一些有用的解决方案,但对我来说不起作用。最后,我在这里发布我的代码:

关于守则:

我想编写一个Java应用程序来检查将音频管理器设置为MODE_IN_CALL的场景

代码:

和xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.AudioBT"
    android:versionCode="1"
    android:versionName="1.0" >
     <Button
               android:id="@+id/setOn"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content" 
               android:text="ON"
               android:onClick="onClick"
               >

           </Button>

<Button   
               android:id ="@+id/setOff"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="OFF" 
               android:onClick="onClick"
               >
               </Button>
 <Button  
               android:id="@+id/strBT"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:onClick="onClick"
                >
               </Button>
  <Button
               android:id ="@+id/stpBT"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content" 
               android:onClick="onClick"
               >
               </Button>


    <uses-sdk android:minSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".AudioBTActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


我一直在使用最新版本的Android SDK 4.0.3和Esclipse IDE for Java

任何帮助都将不胜感激


谢谢

将所有代码放在res/main.xml中

   <Button
               android:id="@+id/setOn"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content" 
               android:text="ON"
               android:onClick="onClick"
               >

           </Button>

<Button   
               android:id ="@+id/setOff"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="OFF" 
               android:onClick="onClick"
               >
               </Button>
 <Button  
               android:id="@+id/strBT"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:onClick="onClick"
                >
               </Button>
  <Button
               android:id ="@+id/stpBT"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content" 
               android:onClick="onClick"
               >
               </Button>


这些xml都来自您的清单吗?如果是这样,您的按钮和内容应该在布局文件中声明,而不是在清单中声明。我想,如果您尝试在这样的清单中声明视图,您会遇到各种奇怪的错误。此外,如果您可以在日志中显示“java.lang.NullPointerException”的行下面发布更多的行,它将告诉您java文件中的哪一行导致了空点。您的清单中不应该有任何布局XML。它需要在自己的XML文件中,在res文件夹中。我是新的,所以我可能会指出错误。如果我用错了术语,请纠正我。我发布的XML代码是从ANDROIDActudio.xml,我认为它是一个布局文件。AndroidManifest.xml不是一个布局文件。如果您签入/res文件夹,应该会看到main.xml。那是一个布局文件。将任何新的XML布局文件添加到该文件夹。在onCreate中,您可以看到它在哪里指定活动正在使用的布局文件:setContentView(R.layout.main);是的,我在/res/layout文件夹中找到了它,建议修改main.xml,现在我可以看到屏幕上的按钮。谢谢大家:)
   <Button
               android:id="@+id/setOn"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content" 
               android:text="ON"
               android:onClick="onClick"
               >

           </Button>

<Button   
               android:id ="@+id/setOff"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="OFF" 
               android:onClick="onClick"
               >
               </Button>
 <Button  
               android:id="@+id/strBT"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:onClick="onClick"
                >
               </Button>
  <Button
               android:id ="@+id/stpBT"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content" 
               android:onClick="onClick"
               >
               </Button>