시작하기 전에 내가 지난 2 일간 오류를 해결하기 위해 주위를 검색하고 있다고 말하며, 나와 함께 작동하지 않는 유용한 해결책을 찾았습니다. SO 마지막으로 나는 여기에 내 코드를 게시하고있다 :안드로이드 응용 프로그램 반환 NULL
을 코드에 대해서 :
내가 MODE_IN_CALL하는 오디오 관리자를 설정하는 시나리오를 확인하는 Java 응용 프로그램을 쓰고 싶었다.
코드 :
public class AudioBTActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button Onbutton = (Button)this.findViewById(R.id.setOn);
Button offButton = (Button)this.findViewById(R.id.setOff);
// listen for the button being hit
Onbutton.setOnClickListener((OnClickListener) this) ;
offButton.setOnClickListener((OnClickListener) this);
}
public void onClick(View v) {
switch(v.getId()) {
case R.id.setOff:
sAudioActivity();
break;
case R.id.setOn :
AudioActivity();
}
Log.e("AudioActivity() failed",null);
}
public void AudioActivity() {
// TODO Auto-generated method stub
AudioManager audioMngr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
boolean isInCall = ((audioMngr.getMode() == AudioManager.MODE_IN_CALL));
if(! isInCall){
audioMngr.setMode(AudioManager.MODE_IN_CALL);
}
}
public void sAudioActivity() {
// TODO Auto-generated method stub
AudioManager audioMngr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioMngr.setMode(AudioManager.MODE_NORMAL);
및 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>
오류 : 01- 31 14 : 36 : 53.424 : E/AndroidRuntime (1309) : java.lang.RuntimeException : 액티비티를 시작할 수 없습니다. ComponentInfo {com.AudioBT/com.AudioBT.AudioBTActivity} : java.lang.NullPointerException
지금까지는 사고의 원인에 도달 할 수 없다. 내 경우 findViewById() returns null for custom component in layout XML, not for other components
내가 자바
어떤 도움을 주시면 감사하겠습니다 안드로이드 SDK 4.0.3 Esclipse IDE의 최신 버전을 사용하고있는 예외를 잡을 수 없습니까 그러나 치는 유사한 스레드, 여기
는<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인가/main.xml에 – FoamyGuy
레이아웃 XML이 없어야합니다 당신의 매니페스트에. 자신의 XML 파일 인 res 폴더에 있어야합니다. – bschultz
나는 새롭기 때문에 내가 잘못 지적 할 수있다. 내가 틀린 용어로 말하면 나를 바로 잡아라. 내가 게시 한 XML 코드는 AndroidManifest.xml에서 가져온 것으로 레이아웃 파일로 간주합니다. –