1
我在學習android,所以我編寫了這段代碼來切換電話鈴聲模式。代碼編譯沒有問題,我在Android Manifest中輸入內容,將內容視圖設置爲所需的佈局,但是我運行此應用程序,出現Force關閉錯誤。誰能告訴我,爲什麼會出現強制關閉錯誤,以便在未來的我應該是找出問題myself.Here是代碼:Android仿真器中的FORCE CLOSE錯誤
package com.umer.practice2;
import android.R.bool;
import android.app.Activity;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;
public class RingerMode extends Activity implements View.OnClickListener {
ToggleButton tb;
ImageView Riv;
TextView tv;
AudioManager mRing;
boolean silent;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.ringermode);
tb.setOnClickListener(this);
InitializeShit();
mRing=(AudioManager) getSystemService(AUDIO_SERVICE);
}
private void InitializeShit() {
// TODO Auto-generated method stub
tb= (ToggleButton) findViewById(R.id.ringTB);
tv= (TextView) findViewById(R.id.ringTV);
Riv= (ImageView) findViewById(R.id.ringIV);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
checkMode();
if(silent)
{
Riv.setImageResource(R.drawable.mysplash);
}else
{
Riv.setImageResource(R.drawable.myscreen);
}
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
checkMode();
}
private void checkMode() {
// TODO Auto-generated method stub
int temp = mRing.getRingerMode();
if(temp==AudioManager.RINGER_MODE_SILENT)
{
tv.setText("Silent");
Riv.setImageResource(R.drawable.mysplash);
silent= true;
}else
if(temp==AudioManager.RINGER_MODE_NORMAL)
{
tv.setText("Normal");
Riv.setImageResource(R.drawable.myscreen);
silent= false;
}
}
非常感謝