안녕하세요, 오랜만에 글 씁니다.
현재 블루투스를 이용하는 App을 개발 중인데
연결 가능한 디바이스 리스트를 Alert를 이용해 띄울 떄 에러와 함께 앱이 종료됩니다.
에러 로그는 (에러 부분 주석으로 표시)
03-27 14:30:05.368 E/AndroidRuntime: FATAL EXCEPTION: main
Process: manager_app, PID: 7556
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:2558)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:4360)
at android.content.res.Resources.getLayout(Resources.java:2372)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at android.support.v7.app.AlertController$AlertParams.createListView(AlertController.java:989)
at android.support.v7.app.AlertController$AlertParams.apply(AlertController.java:965)
at android.support.v7.app.AlertDialog$Builder.create(AlertDialog.java:982)
/////////////////////////////////////////////////////////////////////////여기/////////////
at manager_app.Bluetooth.BluetoothScanUpperAPI21.selectDevice(BluetoothScanUpperAPI21.java:273)
at manager_app.Bluetooth.BluetoothScanUpperAPI21$1.onScanResult(BluetoothScanUpperAPI21.java:189)
/////////////////////////////////////////////////////////////////////////여기/////////////
at android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper$1.run(BluetoothLeScanner.java:413)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7230)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
다음과 같고
코드는 (에러 호출된 부분 주석으로 표시)
public void selectDevice()
{
Log.d(TAG, "selectDevice");
ArrayList<BluetoothDevice> mDevices = bluetoothDeviceList.getDevices();
ArrayList<String> mDeviceNum = bluetoothDeviceList.getDeviceNum();
Log.d(TAG, "mDevices.size: " + mDevices.size() + " / mDeviceNum: " + mDeviceNum.size());
if (mDevices.size() == 3)
{
Toast.makeText(App.getContext(), "There is no Deivce", Toast.LENGTH_SHORT).show();
}
AlertDialog.Builder builder = new AlertDialog.Builder(App.getContext());
builder.setTitle("Choice Device");
final List<String> listItems = new ArrayList<String>();
for (String bt_device : mDeviceNum)
{
listItems.add(bt_device);
}
if (listItems.size() == 0)
{
Log.d(TAG, "No bonded device");
}
else
{
Log.d(TAG, "Find bonded device");
listItems.add("Cancel");
}
final CharSequence[] items = listItems.toArray(new CharSequence[listItems.size()]);
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Dialog dialog_ = (Dialog) dialog;
if (which == mDevices.size() - 1)
{
Toast.makeText(dialog_.getContext(), "Choose cancel", Toast.LENGTH_SHORT).show();
// 취소를 누른 경우
}
else
{
Toast.makeText(dialog_.getContext(), which + " is pushed", Toast.LENGTH_SHORT).show();
}
}
});
builder.setCancelable(false);
/////////////////////////////////////////////////////////////////////////여기/////////////
AlertDialog alert = builder.create();
/////////////////////////////////////////////////////////////////////////여기/////////////
alert.show();
Log.d(TAG, "alert start");
}
와 같습니다.
이리저리 검색해본 결과,
쓰레드에서 UI를 변경해서 그런거다. Context 설정 문제다. 뭔가 초기화를 안했다 등등 있었는데
Toast는 되는걸로 봐서 UI문제는 아닌거 같고, Context도 에러상에서는 걸리는 것 같지 않고..
감이 오질 않습니다.
참고로 이 함수를 실행하고 있는 클래스는 아무것도 상속 받지 않은 클래스 입니다.
ex) public class normalCall {}
어디가 문제 일까요... 정보가 더 필요하실 경우, 말씀해 주시면 더 올리겠습니다.
감사합니다.