I have been trying to follow a tutorial video on Youtube. When I try to look at it in the Emulator as he does in his video the following error appears.
我一直在尝试关注Youtube上的教程视频。当我在他的视频中尝试在模拟器中查看它时,会出现以下错误。
Error:(22, 48) error: ';' expected
错误:(22,48)错误:';'预期
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
错误:任务':app:compileDebugJavaWithJavac'的执行失败。
Compilation failed; see the compiler error output for details.
编译失败;请参阅编译器错误输出以获取详细信
I have done a quick web search and people suggest to check the JDK file location. I have done this which hasn't helped. This is my JDK location.
我做了一个快速的网络搜索,人们建议检查JDK文件位置。我做了这个没有帮助的。这是我的JDK位置。
C:\Program Files\Java\jdk1.8.0_121
This is the small piece of code I copied from the tutorial.
这是我从教程中复制的一小段代码。
package shmaves.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RelativeLayout;
import android.widget.Button;
import android.graphics.Color;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//layout
RelativeLayout shmavesLayout = new RelativeLayout(this);
shmavesLayout.setBackgroundColor(Color.GREEN);
//Button
Button redButton = new Button (this);
redButton.setText ("click me");
redButton.setBackgroundColor(Color.RED)
//Add widget to layout (button is now a child of layout
shmavesLayout.addView(redButton);
//Set this activities content/display to this view
setContentView(shmavesLayout);
}
}
Can anyone shed some light or see where I have gone wrong? I am new to all this so please be thorough with any explanation.
任何人都可以解决一些问题,或者看看我哪里出错了?我是所有这一切的新手,所以请彻底解释。
3 个解决方案
#1
1
The line 22 miss a ";":
第22行错过了“;”:
redButton.setBackgroundColor(Color.RED)
If you are new on Android studio, you may not seeing line number in your IDE, you need to change this configuration:
如果您是Android Studio的新用户,可能无法在IDE中看到行号,则需要更改此配置:
Go to File > Settings. In the dialog, select 'Editor', then the sub-option for 'General', and then the sub-option for 'Appearance'. Select 'Show line numbers' as shown below. Click Ok.
转到文件>设置。在对话框中,选择“编辑器”,然后选择“常规”的子选项,然后选择“外观”的子选项。选择“显示行号”,如下所示。单击确定。
#2
0
Every single statement in Java requires a ;
at the end to denote its end.
Java中的每个语句都需要一个;最后表示它的结束。
The error even tells you that:
该错误甚至告诉您:
';' expected
You just have to find where you missed a semi-colon. Try to find it yourself!
你只需找到错过分号的地方。试着自己找吧!
Answer:
redButton.setBackgroundColor(Color.RED)
#3
0
As the error messages says:
正如错误消息所示:
Error:(22, 48) error: ';' expected
错误:(22,48)错误:';'预期
you forgot the character ';' behind redButton.setBackgroundColor(Color.RED)
你忘了这个角色';'在redButton.setBackgroundColor(Color.RED)后面
#1
1
The line 22 miss a ";":
第22行错过了“;”:
redButton.setBackgroundColor(Color.RED)
If you are new on Android studio, you may not seeing line number in your IDE, you need to change this configuration:
如果您是Android Studio的新用户,可能无法在IDE中看到行号,则需要更改此配置:
Go to File > Settings. In the dialog, select 'Editor', then the sub-option for 'General', and then the sub-option for 'Appearance'. Select 'Show line numbers' as shown below. Click Ok.
转到文件>设置。在对话框中,选择“编辑器”,然后选择“常规”的子选项,然后选择“外观”的子选项。选择“显示行号”,如下所示。单击确定。
#2
0
Every single statement in Java requires a ;
at the end to denote its end.
Java中的每个语句都需要一个;最后表示它的结束。
The error even tells you that:
该错误甚至告诉您:
';' expected
You just have to find where you missed a semi-colon. Try to find it yourself!
你只需找到错过分号的地方。试着自己找吧!
Answer:
redButton.setBackgroundColor(Color.RED)
#3
0
As the error messages says:
正如错误消息所示:
Error:(22, 48) error: ';' expected
错误:(22,48)错误:';'预期
you forgot the character ';' behind redButton.setBackgroundColor(Color.RED)
你忘了这个角色';'在redButton.setBackgroundColor(Color.RED)后面