IllegalArguementException
。permissions
中提供了所有manifest
,列表也似乎不会填充。 Activity
打开后,应用程序崩溃。
公共类照片扩展活动{ 私人处理程序mhandler; public CameraDevice cam; private CameraDevice.StateCallback mcallback;
public void setCallback(CameraDevice.StateCallback callback) {
this.mcallback = callback;
}
public void setHandler(Handler handler) {
this.mhandler = handler;
}
int count=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_photo);
String[] list=new String[10];
CameraManager camera = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
setCallback(mcallback);
setHandler(mhandler);
ListView cami = (ListView) findViewById(R.id.lv);
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.main_photo, R.id.textView2, list);
cami.setAdapter(adapter);
try
{
list = camera.getCameraIdList();
count++;
} catch (CameraAccessException e)
{
e.printStackTrace();
}
try
{
camera.openCamera(list[0], mcallback, mhandler);
mcallback.onOpened(cam);
} catch (CameraAccessException e)
{
e.printStackTrace();
Log.d("Photo", "Error in opening camera");
} catch (IllegalArgumentException a)
{
Log.d("Callback", "Callback Problem");
}
}
答案 0 :(得分:0)
除非我遗漏了某些内容,否则我可以告诉mhandler和mcallback在您对setCallback(mcallback)
和setHandler(mhandler)
的调用中均为空。在致电camera.openCamera(list[0], mcallback, mhandler)
之前,请尝试验证这两个变量。
作为旁注,从不使用数组String[] list=new String[10]
,并且您的变量将在7行之后重新分配。也许相反,使用String[] list;
然后使用7行,使用list = camera.getCameraIdList();
或简单String[] list=camera.getCameraIdList();