2

獲取三星Galaxy設備的攝像頭意圖問題

以下錯誤: -

make sure class name exists is public and has an empty constructor that is public android

調用

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
      startActivityForResult(intent, CAMERA_CODE); 

,當我想例如用於相機的意圖星系設備請任何機構可以幫助關於三星設備問題!

注意: -它可能是重新創建活動,最後有時會崩潰應用程序或圖像不提取所以請幫助我!

堆棧跟蹤: -

java.lang.RuntimeException: Unable to start activity ComponentInfo{MYActivity}: android.app.Fragment$InstantiationException: Unable to instantiate fragment MYFragment: make sure class name exists, is public, and has an empty constructor that is public at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758) at android.app.ActivityThread.access$900(ActivityThread.java:177) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5942) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)

+0

請發佈**整個堆棧跟蹤**。 – CommonsWare

+0

@CommonsWare已經發布了它 – Hardy

回答

0

某處,你有一個片段。該框架不能作爲重新創建活動的一部分被框架實例化。或者:

  • 你的片段是一個內部類(即,不是一個常規的Java類或static嵌套類),或

  • 你的片段不是public,或

  • 你的片段沒有零參數public構造函數

+0

是的,但與其他設備它工作得很好nd我不想爲這部分做太多的硬代碼,所以有沒有簡單的方法呢? – Hardy

+0

@HBdroid:「但與其他設備,它工作正常」 - 不,它不是。您將在配置更改(屏幕旋轉,區域設置更改等)中遇到同樣的崩潰。在這種情況下,您正在運行它,因爲Android在後臺處理時終止了您的進程,釋放了系統RAM,但用戶返回了未完成的任務。這會發生在您還沒有嘗試過的很多相機應用程序以及其他情況下(用戶切換到另一個應用程序15分鐘,然後返回到您的應用程序)。 – CommonsWare

+0

@HBdroid:關於修復,這不僅是簡單的方法,而且是唯一的方法。 – CommonsWare

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"

注意的文件: - 我試了很多例子相機utils的和ofcourse有另一種方式來處理,但對於初學者和對這個核心概念不太熟悉的人會對這個項目更加安心。謝謝!

相關問題