2015-04-23 24 views
0

使用android studio。我一行一行地完成了我的項目代碼,並且沒有紅色突出顯示或下劃線(在.xml,.java文件中)。實際上,沒有任何項目文件具有紅色下劃線。我試圖關閉並重新打開android studio。沒有運氣。當我清理項目時,我收到錯誤消息:無法完成gradle執行 - 原因:讀取超時。其次,當我運行該項目時,我得到錯誤正在運行的應用程序:Gradle項目同步失敗。請修復您的項目並重試。將不勝感激任何幫助。下面的代碼。Android Studio不會在我的代碼中顯示任何錯誤,但Gradle會顯示。試一試

的Java文件:

package com.teamtreehouse.funfacts; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 

public class FunFactsActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_fun_facts); 

//Declare our view variables and assign them the views from the layout file 
    final TextView factlabel = (TextView) findViewById(R.id.factTextView); 
    Button showFactButton = (Button) findViewById(R.id.showFactButton); 
    View.OnClickListener listener = new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
     // The button was clicked so update the fact label with a new fact 
      String fact = "Ostriches can run faster than horses"; 
      factlabel.setText(fact); 
     } 
    }; 
    showFactButton.setOnClickListener(listener); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
// Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.fun_facts, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
} 
    return super.onOptionsItemSelected(item); 
} 
} 

XML文件:

<TextView 
    android:text="Did you know!" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="24sp" 
    android:textColor="#80ffffff" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Ants stretch when they wake up in the morning" 
    android:id="@+id/factTextView" 
    android:layout_centerVertical="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:textSize="24sp"/> 

<Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Show another fun fact" 
    android:id="@+id/showFactButton" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:background="@android:color/white" /> 

</RelativeLayout> 

回答

0

有與Android的代碼沒有問題,你需要先清理項目。

然後刪除你項目中的構建文件(包括lib構建文件)。

然後關閉Studio並重新啓動。建立該項目。我希望它能幫助你。

0

試試這個: 打開您的SDK路徑 並打開構建工具文件夾 此文件夾必須包含1個或多個文件夾,名字是一樣XX.XX其中「x」是一個數字,例如

\ Android的SDK \集結工具\ 19.0.0

,然後打開平臺文件夾(在SDK文件夾),你會看到文件夾名稱是 「Android的XX」,例如

\ Android的SDK \平臺\ android-19

在你的build.gradle

compileSdkVersion 19<-same as the folder (android-19) 
buildToolsVersion "19.0.0"<- same as the folder (19.0.0) 

enter image description here

+0

謝里夫,這是我在我的build.gradle文件中找到。安卓{ compileSdkVersion 21 buildToolsVersion 「21.1.2」 defaultConfig { 的applicationID 「com.example.brian.funfacts」 的minSdkVersion 14 targetSdkVersion 21 的versionCode 1 的versionName 「1.0」 –

+0

你有目錄,你得多compileSdkVersion和buildToolsVersion ..我的意思是這\ Android的SDK \集結工具\ 21.1.2 這 \ Android的SDK \平臺\ Android的21 –

+0

謝里夫,這是我在我的build.gradle文件中發現:機器人{ compileSdkVersion 21 buildToolsVersion「21.1.2」 defaul tConfig applicationId「com.example.brian。funfacts」 的minSdkVersion 14 targetSdkVersion 21 的versionCode 1 的versionName‘1.0’到底什麼是我的下一個步驟。比如我不明白你的意思‘只是這樣做’compileSdkVersion 19 buildToolsVersion‘19.0.0’我也能看起來沒有找到\ android-sdk \目錄 –

1

檢查gradle這個控制檯知道爲什麼gradle這個同步失敗。它在右下方。

你是否從eclipse導入了項目?

檢查您的SDK經理知道,如果你有構建工具,並與您正在使用相同版本的安裝支持Android。

+0

這是幫助我的,我在14歲時擁有最低的SDK版本,但我只有23版本的構建工具。謝謝。將最小值和最大值更改爲23或安裝適當的構建工具。 – CodeMonkey

相關問題