【1】AAPT2 error: check logs for details
File->Settings->Build->Gradle一看path里有中文
最根本的原因是因為user里面的用戶的文件夾是中文的,改成英文就可以了!其他解決方案不做闡述,因為建議改成英文,否則問題無窮!
win10系統以前是中文用戶名改成英文方法:
1、新建一個臨時管理員賬戶
2、登錄管理員賬戶
3、在C:\Users\暖風 改成C:\Users\nf
4、cmd->regedit打開注冊表,找到 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList,然后挨個文件夾打開ProfileImagePath找到你的中文名字,改成英文的就可以了
5、注銷臨時管理員賬戶,登錄以前賬戶,刪除臨時管理員賬戶即可!
【2】Android Studio --“Cannot resolve symbol”
Android Studio 無法識別同一個 package 里的其他類,將其顯示為紅色,但是 compile 沒有問題。鼠標放上去后顯示 “Cannot resolve symbol XXX”,重啟 Android Studio,重新 sync gradle,Clean build 都沒有用。
多半是因為 Android Studio 之前發生了錯誤,某些 setting 出了問題。解決方法如下:
點擊菜單中的 “File” -> “Invalidate Caches / Restart”,然后點擊對話框中的 “Invalidate and Restart”,清空 cache 並且重啟。語法就會正確的高亮了。
【3】Android Switch constant expression required
Android Library工程寫代碼需要注意switch … case語句對資源id的引用,會引發編譯錯誤:case expressions must be constant expressions。
通常android工程生成的資源R.java,資源id聲明如下:
public static final int main=0x7f030004;
而對於library工程,資源id聲明如下:
public static int main=0x7f030004;
缺少了final,因此使用R.id 的switch … case語句會編譯失敗。
解決方案:將switch … case替換成if … else語句。我的后面就沒有問題了,所以沒有替換。
【4】Android 找不到符號
查看是不是沒有導入這類的包,如果沒有導入,直接alt+enter導包就可以了
【5】activity supporting action_view is not set as browsable
應該是要把這個activity設為brosable,那就多加一個category如:
<activity android:name=".ThirdActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http"/>
</intent-filter>
</activity>
Button button1 = (Button) findViewById(R.id.button_1);
button1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.baidu.com/"));//必須是http,如果是https就會報錯
startActivity(intent);
}
});