2017-02-24 78 views
-1

我一直在試圖在Youtube上關注教程視頻。當我嘗試在模擬器中查看它時,他會在他的視頻中看到以下錯誤。如何解決「錯誤:';'預計「Android Studio中的錯誤?

Error:(22, 48) error: ';' expected

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

我已經做了一個快速的網絡搜索,並且人們建議檢查JDK文件的位置。我已經做到了這一點,但沒有幫助。這是我的JDK位置。

C:\Program Files\Java\jdk1.8.0_121 

這是我從教程中複製的一小段代碼。

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); 

} 
} 

任何人都可以擺脫一些光線或看看我哪裏出了錯?我對這一切都很陌生,所以請詳細解釋。

回答

0

Java中的每一條語句都需要末尾的;來表示它的結尾。

的錯誤,甚至告訴你:

';' expected

你必須要找到你錯過了一個分號。嘗試自己找到它!

答:

redButton.setBackgroundColor(Color.RED)

+0

這工作。謝謝!我不知道這是什麼意思。 – Shmaves

0

由於錯誤消息說:

Error:(22, 48) error: ';' expected

您忘記字符 ';'背後redButton.setBackgroundColor(Color.RED)

+0

這工作,謝謝堆!我會更加關注! – Shmaves

1

線22小姐「;」:

redButton.setBackgroundColor(Color.RED) 

如果您在Android工作室新的,你可能不會在你的IDE看到行號,您需要更改此配置:

轉到文件>設置。在對話框中,選擇「編輯器」,然後選擇「常規」的 子選項,然後選擇「外觀」的子選項。 選擇'顯示行號',如下所示。點擊確定。

+0

「;」謝謝。他在他的教程中介紹了行號,我只是沒有複製它們。感謝您的輸入。 – Shmaves