問題預覽
- 1)怎麼判斷EditText是否爲空?
- 2)創建java類中類出現is not an enclosing class
- 3)關於String.replace
- 4)Error type 3 Error: Activity class {} does not exist
- 5)Failed to open zip file. Gradle’s dependency cache may be corrupt
(this sometimes occurs after a network connection timeout.)
1.怎麼判斷EditText是否爲空?
- 用
TextUtils.isEmpty(XX.getText())
來判斷
TextUtils.isEmpty()在字符串爲null或者"“的情況下,都是可以用TextUtils.isEmpty()來進行判斷的,因爲當”"情況下,str.length()==0,所以同樣也會返回true。
2.創建java類中類出現is not an enclosing class
public class A {
public class B {
}
};
需要實例B類時,使用A.B ab = new A.B();
會出現一個錯誤 “is not an enclosing class”
解決辦法:
A a = new A();
A.B ab = a.new B();
沒有靜態(static)的類中類不能使用外部類進行.操作,必須用實例來進行實例化類中類。
3.關於String.replace
String對象是不可變的。
public String replace(char oldChar,char newChar)
返回使用newChar替換此字符串中所有出現的oldChar而產生的字符串,需要一個返回值。
4.Error type 3 Error: Activity class {} does not exist
- 部分手機在點擊應用卸載以後,再用AndroidStudio往手機上run程序一直報錯,Activity class {} does not exist,解決辦法:
adb uninstall {com.xxx.xxx(包名)}
,卸載apk包。
5.Failed to open zip file. Gradle’s dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
- 解決方法:在gradle鏈接中:https://services.gradle.org/distributions/
找到你需要的版本號。下載並解壓到此目錄中:C:\Users\Administrator.gradle\wrapper\dists。
之後在AS中打開設置:File->settings。