获得
低于错误: -
致电时确保类名存在是公共的,并且有一个空的构造函数是public android
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_CODE);
我想要用于相机意图的Galaxy设备的示例,请任何身体可以帮助解决三星设备问题!
注意: - 它可能正在重新创建活动,最终有时会崩溃应用图片无法抓取,所以请帮助我!
堆栈跟踪: -
java.lang.RuntimeException:无法启动活动ComponentInfo {MYActivity}:android.app.Fragment $ InstantiationException:无法实例化片段MYFragment:确保类名存在,是公共的,并且具有一个公共的空构造函数 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758) 在android.app.ActivityThread.access $ 900(ActivityThread.java:177) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1448) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:145) 在android.app.ActivityThread.main(ActivityThread.java:5942) at java.lang.reflect.Method.invoke(Native Method) 在java.lang.reflect.Method.invoke(Method.java:372) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1388) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
答案 0 :(得分:2)
在我自己找到的答案这里是最好的例子,它是自己烦恼的设备!
AndroidCameraUtils - 下载项目,并从库项目中包含以下内容,您可以使用的代码片段!
private void setupCameraIntentHelper() {
mCameraIntentHelper = new CameraIntentHelper(this, new CameraIntentHelperCallback() {
@Override
public void onPhotoUriFound(Date dateCameraIntentStarted, Uri photoUri, int rotateXDegrees) {
messageView.setText(getString(R.string.activity_camera_intent_photo_uri_found) + photoUri.toString());
Bitmap photo = BitmapHelper.readBitmap(CameraIntentActivity.this, photoUri);
if (photo != null) {
photo = BitmapHelper.shrinkBitmap(photo, 300, rotateXDegrees);
ImageView imageView = (ImageView) findViewById(de.ecotastic.android.camerautil.sample.R.id.activity_camera_intent_image_view);
imageView.setImageBitmap(photo);
}
}
@Override
public void deletePhotoWithUri(Uri photoUri) {
BitmapHelper.deleteImageWithUriIfExists(photoUri, CameraIntentActivity.this);
}
@Override
public void onSdCardNotMounted() {
Toast.makeText(getApplicationContext(), getString(R.string.error_sd_card_not_mounted), Toast.LENGTH_LONG).show();
}
@Override
public void onCanceled() {
Toast.makeText(getApplicationContext(), getString(R.string.warning_camera_intent_canceled), Toast.LENGTH_LONG).show();
}
@Override
public void onCouldNotTakePhoto() {
Toast.makeText(getApplicationContext(), getString(R.string.error_could_not_take_photo), Toast.LENGTH_LONG).show();
}
@Override
public void onPhotoUriNotFound() {
messageView.setText(getString(R.string.activity_camera_intent_photo_uri_not_found));
}
@Override
public void logException(Exception e) {
Toast.makeText(getApplicationContext(), getString(R.string.error_sth_went_wrong), Toast.LENGTH_LONG).show();
Log.d(getClass().getName(), e.getMessage());
}
});
}
@Override
protected void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
mCameraIntentHelper.onSaveInstanceState(savedInstanceState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mCameraIntentHelper.onRestoreInstanceState(savedInstanceState);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
mCameraIntentHelper.onActivityResult(requestCode, resultCode, intent);
}
}
android:configChanges="keyboardHidden|orientation|screenSize"
注意: - 我尝试了许多相机工具的例子,当然还有另外一种方法可以处理它但是对于初学者和那些对核心概念不太熟悉的人来说会更舒适项目。谢谢!
答案 1 :(得分:0)
某处,你有一个片段。作为重新创建活动的一部分,框架无法将该片段实例化。之一:
您的片段是内部类(即,不是常规Java类或static
嵌套类),或
您的片段不是public
或
您的片段没有零参数public
构造函数