Android蓝牙聊天应用程序意外停止

时间:2013-03-23 15:25:40

标签: android forceclose

我即将创建蓝牙聊天应用。我将它安装在我的手机上,当启动它时,它会显示一条包含强制关闭按钮的错误消息。我的启动活动显示没有错误。它在下面给出:

package com.group6.abc;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity{

private BluetoothAdapter mBluetoothAdapter=null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if(mBluetoothAdapter==null){
        Toast.makeText(this, "Bluetooth Is Not Available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    Button btn_start=(Button) findViewById(R.id.start);
    btn_start.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            Intent intent=new Intent(MainActivity.this,FirstActivity.class);
            startActivity(intent);
        }
    });
}       

public void onStart(){
    super.onStart();
    if(!mBluetoothAdapter.isEnabled()){
        Intent enableIntent=new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent,3);
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
    }
}

我身边有错误吗?有人请帮助我。

谢谢...

0 个答案:

没有答案