2016-06-17 4 views
11

TAG이 언급 된 경우를 제외하고 내 활동의 거의 모든 항목이 정상적으로 작동합니다. TAG 빨간 선을 얻고 'TAG' has private access in 'android.support.v4.app.FragmentActivity'라고 말합니다. 나는 이것이 무엇을 의미하는지에 대한 단서가 없으므로 여기서 나를 도와주세요. (수입 제외)'TAG'에는 'android.support.v4.app.FragmentActivity'의 개인 액세스 권한이 있습니다.

MainActivity -

public class MainActivity extends AppCompatActivity { 
    public static final String DATA_PATH = Environment 
      .getExternalStorageDirectory().toString() + "/MainActivity"; 
    public static final String lang = "eng"; 

    protected Button _button; 
    protected ImageView _image; 
    protected TextView _field; 
    protected String _path; 
    protected boolean _taken; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     String[] paths = new String[] { DATA_PATH, DATA_PATH + "tessdata/" }; 

     for (String path : paths) { 
      File dir = new File(path); 
      if (!dir.exists()) { 
       if (!dir.mkdirs()) { 
        Log.v(TAG, "ERROR: Creation of directory " + path + " on sdcard failed"); 
        return; 
       } else { 
        Log.v(TAG, "Created directory " + path + " on sdcard"); 
       } 
      } 

     } 

     if (!(new File(DATA_PATH + "tessdata/" + lang + ".traineddata")).exists()) { 
      try { 

       AssetManager assetManager = getAssets(); 
       InputStream in = assetManager.open("tessdata/" + lang + ".traineddata"); 
       //GZIPInputStream gin = new GZIPInputStream(in); 
       OutputStream out = new FileOutputStream(DATA_PATH 
         + "tessdata/" + lang + ".traineddata"); 

       // Transfer bytes from in to out 
       byte[] buf = new byte[1024]; 
       int len; 
       //while ((lenf = gin.read(buff)) > 0) { 
       while ((len = in.read(buf)) > 0) { 
        out.write(buf, 0, len); 
       } 
       in.close(); 
       //gin.close(); 
       out.close(); 

       Log.v(TAG, "Copied " + lang + " traineddata"); 
      } catch (IOException e) { 
       Log.e(TAG, "Was unable to copy " + lang + " traineddata " + e.toString()); 
      } 
     } 

     _image = (ImageView) findViewById(R.id.image); 
     _field = (TextView) findViewById(R.id.field); 
     _button = (Button) findViewById(R.id.button); 
     _button.setOnClickListener(new ButtonClickHandler()); 

     _path = Environment.getExternalStorageDirectory() + "/Login Data.jpg"; 
    } 

    public class ButtonClickHandler implements View.OnClickListener 
    { 
     public void onClick(View view){ 
      startCameraActivity(); 
     } 
    } 

    protected void startCameraActivity() 
    { 
     File file = new File(_path); 
     Uri outputFileUri = Uri.fromFile(file); 

     Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
     intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); 

     startActivityForResult(intent, 0); 
    } 

    protected void onPhotoTaken() 
    { 
     _taken = true; 

     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inSampleSize = 4; 

     Bitmap bitmap = BitmapFactory.decodeFile(_path, options); 
     _image.setImageBitmap(bitmap); 

     _field.setVisibility(View.GONE); 

     ExifInterface exif = new ExifInterface(_path); 

     int exifOrientation = exif.getAttributeInt(
       ExifInterface.TAG_ORIENTATION, 
       ExifInterface.ORIENTATION_NORMAL); 

     int rotate = 0; 

     switch (exifOrientation) { 
      case ExifInterface.ORIENTATION_ROTATE_90: 
       rotate = 90; 
       break; 
      case ExifInterface.ORIENTATION_ROTATE_180: 
       rotate = 180; 
       break; 
      case ExifInterface.ORIENTATION_ROTATE_270: 
       rotate = 270; 
       break; 
     } 

     if (rotate != 0) { 
      int w = bitmap.getWidth(); 
      int h = bitmap.getHeight(); 

      // Setting pre rotate 
      Matrix mtx = new Matrix(); 
      mtx.preRotate(rotate); 

      // Rotating Bitmap & convert to ARGB_8888, required by tess 
      bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false); 
     } 
     bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true); 

     TessBaseAPI baseApi = new TessBaseAPI(); 
     baseApi.init(DATA_PATH, lang); 
     baseApi.setImage(bitmap); 
     String recognizedText = baseApi.getUTF8Text(); 
     baseApi.end(); 
    } 

    @Override 
    protected void onSaveInstanceState(Bundle outState) { 
     outState.putBoolean(MainActivity.PHOTO_TAKEN, _taken); 
    } 

    @Override 
    protected void onRestoreInstanceState(Bundle savedInstanceState) 
    { 
     Log.i("MakeMachine", "onRestoreInstanceState()"); 
     if(savedInstanceState.getBoolean(MainActivity.PHOTO_TAKEN)) { 
      onPhotoTaken(); 
     } 
    } 
+0

[FragmentActivity] (https://github.com/android/platform_frameworks_support/blob/master/v4/java/android/support/v4/app/FragmentActivity.java#L82)의 소스 코드를 살펴보면 82 행의 'TAG'은 비공개입니다. –

+0

공개해야합니까? –

+0

잠긴 것 같습니다 –

답변

22

당신은 MainActivity에 태그에 대한 상수를 정의해야합니다 :

private static final String TAG = "MainActivity" 
+0

고마워요! 그것은 효과가있다! –

5

는 다음

private static final String TAG = MainActivity.class.getSimpleName(); 

당신은이 필드를 사용하여 시도 귀하의 모든 활동 또는 단편에 저장하십시오.

관련 문제