简体   繁体   English

“TAG”在“android.support.v4.app.FragmentActivity”中有私有访问权限

[英]'TAG' has private access in 'android.support.v4.app.FragmentActivity'

Almost everything in my activity is working fine, except for wherever TAG is referenced.除了引用TAG的任何地方,我的活动中几乎所有内容都运行良好。 TAG gets a red line and says: 'TAG' has private access in 'android.support.v4.app.FragmentActivity' . TAG得到一条红线并说: 'TAG' has private access in 'android.support.v4.app.FragmentActivity'

MainActivity (without imports)- 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();
        }
    }

您应该在MainActivity为您的标签定义一个常量:

private static final String TAG = "MainActivity"

try the following尝试以下

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

You can use this field in your any Activity or Fragment.您可以在任何活动或片段中使用此字段。

Well that's just an Android's way of telling us that we haven't defined TAG.好吧,这只是 Android 告诉我们尚未定义 TAG 的方式。 To define the TAG in the current file, we can go to MainActivity Class and type "logt", you will get some auto code suggestions from Android studio, press enter there and you will get following code要在当前文件中定义 TAG,我们可以转到 MainActivity Class 并输入“logt”,您将获得来自 Android Studio 的一些自动代码建议,在那里按回车,您将获得以下代码

private static final String TAG = "MainActivity";

Once you add this to your code, your error will be gone一旦你将它添加到你的代码中,你的错误就会消失

Practical note: following is the better approach实用说明:以下是更好的方法

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

as compared to:相比之下:

private static final String TAG = "MainActivity";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在ViewModelProviders中解析android.support.v4.app.FragmentActivity的方法 - Cannot resolve method of android.support.v4.app.FragmentActivity in ViewModelProviders 无法将ContraceptiveFragment中的ContraceptiveFragment()应用于(android.support.v4.app.FragmentActivity) - ContraceptiveFragment( ) in ContraceptiveFragment cannot be applied to (android.support.v4.app.FragmentActivity) “无法找到类'android.support.v4.app.FragmentActivity'”错误 - “Could not find class 'android.support.v4.app.FragmentActivity'” Error 将 android.support.v4.app.FragmentActivity$NonConfigurationInstances 转换为我的 AsyncTask 时出错 - Error casting android.support.v4.app.FragmentActivity$NonConfigurationInstances to my AsyncTask TAG And UpdateUI在FragmentActivity错误中对LoginActivity.java具有私有访问权限 - TAG And UpdateUI has private access in FragmentActivity Error For LoginActivity.java 尝试调用虚拟方法'android.content.Context android.support.v4.app.FragmentActivity.getApplicationContext()'android - Attempt to invoke virtual method 'android.content.Context android.support.v4.app.FragmentActivity.getApplicationContext()' android android.support.v4.app.fragment和androidx.fragment.app.FragmentActivity有什么区别 - What is the difference between android.support.v4.app.fragment and androidx.fragment.app.FragmentActivity Javah:错误:无法访问android.support.v7.app.ActionBarActivity - Javah: Error: cannot access android.support.v7.app.ActionBarActivity 'Person()' 在 'android.app.Person' 中具有私有访问权限 - 'Person()' has private access in 'android.app.Person' 如何修复android中的“无法访问android.support.v4.app.ActivityCompat未找到的ActivityCompat类文件”错误? - How to fix "cannot access ActivityCompat class file for android.support.v4.app.ActivityCompat not found" error in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM