英文:
illegal start of type, <identifier> expected, ';' expected errors
问题
我尝试仅在构建类型为"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) {
^
英文:
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("eng")) {
^
error: /home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:106: error: <identifier> expected
if (android.os.Build.TYPE.equals("eng")) {
^
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("eng")) {
^
error: /home/android/lineage-17.1/frameworks/base/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java:108: error: ';' 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: ';' 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: ';' 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("eng")) {
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("eng")) {
@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("eng")) {
setBuildText();
}
}
};
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论