여기에 새롭고 java에 처음 나왔습니다. 내 첫 번째 프로젝트에서 작업했습니다. 활동에 새로운 버튼을 추가하고 앱이 시작하지 않을 때까지 모두 훌륭했습니다. (태블릿에서)치명적인 예외 : 수신기가 등록되지 않았습니까?
변경 사항을 원래 상태로 되 돌렸지 만 여전히이 문제가 발생했습니다.이 코드는 이전에 잘 작동 했었고 인생의 이유로 나올 수 없었습니다!
내 응용 프로그램에는 두 가지 활동이 있습니다. 실행 활동은 블루투스 설정 페이지입니다 (또는 완료 될 때). 블루투스를 켜거나 끄고, 장치를 검색하고, 페어링 된 장치를 나열하고, 전환 할 단추가있는 버튼이 있습니다. 두 번째 액티비티는 아직 끝나지 않은 액션을 수행하기위한 버튼과 첫 번째 액티비티로 돌아가는 뒤로 버튼입니다.
처음부터 두 번째 활동으로 변경하면 "불행하게도 bluetoothtest가 중지되었습니다."라는 메시지가 나타납니다.
을 heres 로그 캣 오류 :이 밤은 올바르게 형식의 경우 임 죄송합니다, 이건 내 처음으로
07-07 16:01:38.757: D/AndroidRuntime(3595): Shutting down VM
07-07 16:01:38.757: W/dalvikvm(3595): threadid=1: thread exiting with uncaught exception (group=0x40d89930)
07-07 16:01:38.757: E/AndroidRuntime(3595): FATAL EXCEPTION: main
07-07 16:01:38.757: E/AndroidRuntime(3595): java.lang.RuntimeException: Unable to destroy activity {com.javacodegeeks.android.bluetoothtest/sjtech.rompa.wifi.Bluetoothsetup}:java.lang.IllegalArgumentException: Receiver not registered: [email protected]
07-07 16:01:38.757: E/AndroidRuntime(3595): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3586)
07-07 16:01:38.757: E/AndroidRuntime(3595): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3605)
07-07 16:01:38.757: E/AndroidRuntime(3595): at android.app.ActivityThread.access$1300(ActivityThread.java:158)
07-07 16:01:38.757: E/AndroidRuntime(3595): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
07-07 16:01:38.757: E/AndroidRuntime(3595): at android.os.Handler.dispatchMessage(Handler.java:99)
07-07 16:01:38.757: E/AndroidRuntime(3595): at android.os.Looper.loop(Looper.java:176)
07-07 16:01:38.757: E/AndroidRuntime(3595): at android.app.ActivityThread.main(ActivityThread.java:5365)
07-07 16:01:38.757: E/AndroidRuntime(3595): at java.lang.reflect.Method.invokeNative(Native Method)
07-07 16:01:38.757: E/AndroidRuntime(3595): at java.lang.reflect.Method.invoke(Method.java:511)
07-07 16:01:38.757: E/AndroidRuntime(3595): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
07-07 16:01:38.757: E/AndroidRuntime(3595): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
07-07 16:01:38.757: E/AndroidRuntime(3595): at dalvik.system.NativeStart.main(Native Method)
07-07 16:01:38.757: E/AndroidRuntime(3595): Caused by: java.lang.IllegalArgumentException: Receiver not registered: [email protected]
07-07 16:01:38.757: E/AndroidRuntime(3595): at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:662)
07-07 16:01:38.757: E/AndroidRuntime(3595): at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1707)
07-07 16:01:38.757: E/AndroidRuntime(3595): at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:452)
07-07 16:01:38.757: E/AndroidRuntime(3595): at sjtech.rompa.wifi.Bluetoothsetup.onDestroy(Bluetoothsetup.java:233)
07-07 16:01:38.757: E/AndroidRuntime(3595): at android.app.Activity.performDestroy(Activity.java:5495)
07-07 16:01:38.757: E/AndroidRuntime(3595): at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1127)
07-07 16:01:38.757: E/AndroidRuntime(3595): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3573)
07-07 16:01:38.757: E/AndroidRuntime(3595): ... 11 more
07-07 16:01:39.976: I/Process(3595): Sending signal. PID: 3595 SIG: 9
입니다
. 바로 생각에 unregisterReciever 또는 시작 응용 프로그램의 첫 페이지의 폐쇄에 관련package sjtech.rompa.wifi;
import android.os.Bundle;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.BroadcastReceiver;
import android.content.Context;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Set;
import java.util.UUID;
import com.javacodegeeks.android.bluetoothtest.R;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class Bluetoothsetup extends Activity {
private static final int REQUEST_ENABLE_BT = 1;
//private static final String TAG = null;
private Button onBtn;
private Button offBtn;
private Button listBtn;
private Button findBtn;
public Button wifiscreen;
private TextView text;
public BluetoothAdapter myBluetoothAdapter;
private Set<BluetoothDevice> pairedDevices;
private ListView myListView;
private ArrayAdapter<String> BTArrayAdapter;
private ProgressBar progressBar1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bluetoothsetup);
// take an instance of BluetoothAdapter - Bluetooth radio
myBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
//if the device doesnt have bluetooth disable all buttons
if(myBluetoothAdapter == null) {
onBtn.setEnabled(false);
offBtn.setEnabled(false);
listBtn.setEnabled(false);
findBtn.setEnabled(false);
//set 'status' to show:
text.setText("Status: not supported");
//show toast with comment:
Toast.makeText(getApplicationContext(),"Your device does not support Bluetooth",
Toast.LENGTH_LONG).show();
//if device has bluetooth set on click listener's for buttons
} else {
text = (TextView) findViewById(R.id.text);
onBtn = (Button)findViewById(R.id.turnOn);
onBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
on(v);
}
});
offBtn = (Button)findViewById(R.id.turnOff);
offBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
off(v);
}
});
listBtn = (Button)findViewById(R.id.paired);
listBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
list(v);
}
});
findBtn = (Button)findViewById(R.id.search);
findBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
find(v);
}
});
wifiscreen = (Button)findViewById(R.id.wifiscreen);
wifiscreen.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//Button wifiscreen changes from bluetooth to wifi page
Intent intent = new Intent(v.getContext(), Wifi.class);
startActivity(intent);
}
});
myListView = (ListView)findViewById(R.id.listView1);
// setForeground(Color.RED);
// create the arrayAdapter that contains the BTDevices, and set it to the ListView
BTArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
myListView.setAdapter(BTArrayAdapter);
}
}
//if bluetooth is turned on request android bluetooth start request
public void on(View view){
if (!myBluetoothAdapter.isEnabled()) {
Intent turnOnIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnOnIntent, REQUEST_ENABLE_BT);
//show message for bluetooth start
Toast.makeText(getApplicationContext(),"Bluetooth turned on" ,
Toast.LENGTH_LONG).show();
//show message for bluetooth already on
}
else{
Toast.makeText(getApplicationContext(),"Bluetooth is already on",
Toast.LENGTH_LONG).show();
}
}
// set 'status' to bluetooth status
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if(requestCode == REQUEST_ENABLE_BT){
if(myBluetoothAdapter.isEnabled()) {
text.setText("Status: Enabled");
} else {
text.setText("Status: Disabled");
}
}
}
public void list(View view){
// get paired devices
pairedDevices = myBluetoothAdapter.getBondedDevices();
// put it's one to the adapter
for(BluetoothDevice device : pairedDevices)
BTArrayAdapter.add(device.getName()+ "\n" + device.getAddress());
// display toast message
Toast.makeText(getApplicationContext(),"Show Paired Devices",
Toast.LENGTH_SHORT).show();
}
final BroadcastReceiver bReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// add the name and the MAC address of the object to the arrayAdapter
BTArrayAdapter.add(device.getName() + "\n" + device.getAddress());
BTArrayAdapter.notifyDataSetChanged();
}
}
};
public void find(View view) {
if (myBluetoothAdapter.isDiscovering()) {
//if the button is pressed when it discovers, cancel the discovery
myBluetoothAdapter.cancelDiscovery();
}
else {
BTArrayAdapter.clear();
myBluetoothAdapter.startDiscovery();
registerReceiver(bReceiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));
}
}
// show 'status' that bluetooth is disabled
public void off(View view){
myBluetoothAdapter.disable();
text.setText("Status: Disconnected");
//show toast that bluetooth is disabled
Toast.makeText(getApplicationContext(),"Bluetooth turned off",
Toast.LENGTH_LONG).show();
}
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(bReceiver);
}
}
내가 생각 :
이
내가 오류가 발생 생각하는 첫 페이지 된 .java입니다 두 번째 활동? 두 번째 활동으로 변경하면 앱이 닫히는 지점이지만 닫히는 것처럼 보이고 완전히 닫히지 않고 첫 번째 활동으로 되돌아갑니다.앞에서 언급했듯이이 정확한 코드는 정상적으로 작동했으며이 오류는 아무데도 나타나지 않고 버튼 하나만 추가하여 다른 작업을 보냈습니다.
다른 코드가 도움이 필요하시면 기꺼이 제공해주십시오!
미리 감사드립니다.
'onStop()/onPause()'에서도'unregisterReceiver (bReceiver);를 등록 해제 하시겠습니까? 수신기를 어디에서 등록하고 있습니까? – TheLostMind
전체 코드를 보여줍니다 ... 어디에서'find()'를 호출합니까? – TheLostMind