非法的类型起始,应为<标识符>,应为';'的错误。

huangapple go评论73阅读模式
英文:

illegal start of type, <identifier> expected, ';' expected errors

问题

我的代码:
https://github.com/LightningFastRom/android_frameworks_base/blob/next-20200913/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java

我尝试仅在构建类型为"eng"时显示构建号。但是在编译时出现了许多错误:

错误:/home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:106: 错误:非法的类型起始
        if (android.os.Build.TYPE.equals("eng")) {
        ^
错误:/home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:106: 错误:预期<标识符>
        if (android.os.Build.TYPE.equals("eng")) {
                                        ^
错误:/home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:106: 错误:非法的类型起始
        if (android.os.Build.TYPE.equals("eng")) {
                                         ^
错误:/home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:108: 错误:应有';'
            public void onChange(boolean selfChange, Uri uri) {
                                ^
错误:/home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:108: 错误:应有';'
            public void onChange(boolean selfChange, Uri uri) {
                                                        ^
错误:/home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:108: 错误:不是语句
            public void onChange(boolean selfChange, Uri uri) {
                                                         ^
错误:/home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:108: 错误:应有';'
            public void onChange(boolean selfChange, Uri uri) {
                                                            ^
英文:

My code:
https://github.com/LightningFastRom/android_frameworks_base/blob/next-20200913/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java

I am trying to set that only if the build type is eng it will show the build number. But there's a lot of errors when compiling:

error: /home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:106: error: illegal start of type
        if (android.os.Build.TYPE.equals(&quot;eng&quot;)) {
        ^
error: /home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:106: error: &lt;identifier&gt; expected
        if (android.os.Build.TYPE.equals(&quot;eng&quot;)) {
                                        ^
error: /home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:106: error: illegal start of type
        if (android.os.Build.TYPE.equals(&quot;eng&quot;)) {
                                         ^
error: /home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:108: error: &#39;;&#39; expected
            public void onChange(boolean selfChange, Uri uri) {
                                ^
error: /home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:108: error: &#39;;&#39; expected
            public void onChange(boolean selfChange, Uri uri) {
                                                        ^
error: /home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:108: error: not a statement
            public void onChange(boolean selfChange, Uri uri) {
                                                         ^
error: /home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:108: error: &#39;;&#39; expected
            public void onChange(boolean selfChange, Uri uri) {
                                                            ^

答案1

得分: 1

它的语法错误,大括号未正确闭合

尝试这样修改:

private final ContentObserver mDeveloperSettingsObserver = new ContentObserver(
        new Handler(mContext.getMainLooper())) {
    @Override
    public void onChange(boolean selfChange, Uri uri) {
        if (android.os.Build.TYPE.equals("eng")) {
            super.onChange(selfChange, uri);
            setBuildText();
        }
    }
};
英文:

Its syntax error braces not closed properly

try this:

    private final ContentObserver mDeveloperSettingsObserver = new ContentObserver(
            new Handler(mContext.getMainLooper()) {
                @Override
                public void onChange(boolean selfChange, Uri uri) {
                    if (android.os.Build.TYPE.equals(&quot;eng&quot;)) {
                        super.onChange(selfChange, uri);
                        setBuildText();
        
                    }
                }});

答案2

得分: 0

你的代码中有问题,请检查这个函数:

private final ContentObserver mDeveloperSettingsObserver = new ContentObserver(
        new Handler(mContext.getMainLooper())) {
    if (android.os.Build.TYPE.equals("eng")) {
        @Override
        public void onChange(boolean selfChange, Uri uri) {
            super.onChange(selfChange, uri);
            setBuildText();
        }
    }
};

// new Handler(...),是一个函数式接口,你只能在onChange方法内编写代码,在构造函数后的大括号是类体,你不能在那里编写语句,所以将你的检查放在函数内部。这样可以编译通过。

英文:

You have problem in your code, please check this function

private final ContentObserver mDeveloperSettingsObserver = new ContentObserver(
                new Handler(mContext.getMainLooper())) {
        if (android.os.Build.TYPE.equals(&quot;eng&quot;)) {
            @Override
            public void onChange(boolean selfChange, Uri uri) {
                super.onChange(selfChange, uri);
                setBuildText();
            }
        }
    };

// new Handler(...) { }, is a functional interface and you can only write inside th `onChange` method , curly braces after constructor is class body, you cannot write statements there, so put your checks inside the function. It will compile.

答案3

得分: 0

我可以看到在L104到L113行有问题。你试图基于一个if条件来覆盖方法,这是不允许的。你需要将条件放在方法定义本身。

private final ContentObserver mDeveloperSettingsObserver = new ContentObserver(
            new Handler(mContext.getMainLooper())) {
    @Override
    public void onChange(boolean selfChange, Uri uri) {
        super.onChange(selfChange, uri);
        // 在这里加入if条件
        if (android.os.Build.TYPE.equals("eng")) {
            setBuildText();
        }
    }
};
英文:

I can see issue at lines L104 to L113. You are trying to override method based on an if condition which is not allowed. You need to put condition in method definition itself.

private final ContentObserver mDeveloperSettingsObserver = new ContentObserver(
            new Handler(mContext.getMainLooper())) {
    @Override
    public void onChange(boolean selfChange, Uri uri) {
        super.onChange(selfChange, uri);
        // put if condition here
        if (android.os.Build.TYPE.equals(&quot;eng&quot;)) {
             setBuildText();
        }
    }
};

huangapple
  • 本文由 发表于 2020年9月15日 11:17:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/63894558.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定