android开发中遇到的问题汇总【九】
244.http请求的url含有中字符时,需要Uri编码。Uri.encoder()
245.使用androidstudio时,不知道什么原因svn不见了
Android Studio missing Subversion plugin
Please make sure that the “SubversionIntegration” plugin is enabled in Preferences > Plugins
246.Error:Execution failed for task ‘:app:dexDebug’.> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/home/xxx/tools/android/jdk1.7.0_71/bin/java” finished with non-zero exit value 2
检查下是否多次引用同一个jar包
以下情况
1. module下jar包版本不同
同一个module 在libs中包含乐.jar,而在src下又把相应的source页加入了
gradle中是否重复编译,
比如
已经加了compile fileTree(include: [‘*.jar’], dir: ‘libs’)
然而在下面又加一句compile files(‘libs/xxx.jar’)
参考 Error:Execution failed for task ‘:app:dexDebug’. com.android.ide.common.process.ProcessException
246.android handler的警告Handler Class Should be Static or Leaks Occur
在使用Handler更新UI的时候public class SampleActivity extends Activity {
private final Handler mLeakyHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO
}
}
}会包上述warning 会导致内存泄露
原因在于匿名内部类handler持有activity的引用,当activity finish后 handler还没有处理完,导致activity的view和resource资源不能得到释放,导致内存泄露
针对这个问题google官方给出了正确的做法
通过静态内部类 包含activity的弱引用来处理。
public class SampleActivity extends Activity {
/**
* Instances of static inner classes do not hold an implicit
* reference to their outer class.
*/
private static class MyHandler extends Handler {
private final WeakReference mActivity;
public MyHandler(SampleActivity activity) {
mActivity = new WeakReference(activity);
}
@Override
public void handleMessage(Message msg) {
SampleActivity activity = mActivity.get();
if (activity != null) {
// ...
}
}
}
private final MyHandler mHandler = new MyHandler(this);
/**
* Instances of anonymous classes do not hold an implicit
* reference to their outer class when they are “static”.
*/
private static final Runnable sRunnable = new Runnable() {
@Override
public void run() { }
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Post a message and delay its execution for 10 minutes.
mHandler.postDelayed(sRunnable, 60 * 10 * 1000);
// Go back to the previous Activity.
finish();
}
}
参考android handler的警告Handler Class Should be Static or Leaks Occur
247.androidstudio不同tab切换 ctrl+tab
248.androidstudio 如何自动import用到的类或接口?
For Windows/Linux, you can go to File -> Settings -> Editor -> General -> Auto Import -> Java and make the following changes:
change Insert imports on paste value to All
markAdd unambigious imports on the fly option as checked
On a Mac, do the same thing in Android Studio -> Preferences
参考What is the shortcut to Auto import all in Android Studio?
249.Android NDK: Could not find application project directory ! Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/home/cenuser/android/android-ndk-r7b/build/core/build-local.mk:130: *** Android NDK: Aborting . Stop.
cd到jni目录。或者 ndk-build -C your_project_path
250 .Why do I want to avoid non-default constructors in fragments? fragment设置参数正确的做法
Make a bundle object and insert your data (in this example your Category object). Be careful, you can't pass this object directly into the bundle, unless it's serializable. I think it's better to build your object in the fragment, and put only an id or something else into bundle. This is the code to create and attach a bundle:
Bundle args = new Bundle();
args.putLong("key", value);
yourFragment.setArguments(args);
After that, in your fragment access data:
Type value = getArguments().getType("key");
That's all.
251. ubuntu下删除.svn的方法
find -type d -name '.svn' -exec rm -rfv {} \;
参考 http://blog.csdn.net/zhaoyu7777777/article/details/9445717
252. Fatal : Could not read from remote repository.
git配置使用,已经把公钥发给发给服务端,在终端命令行也是可以正常的pull push,但是在androidstudio push或者pull的时候确出现上述错误
解决方式
setting –> Version Control –>Git ,In the SSH executable dropdown, choose Native
253. ubuntu获取证书指纹的命令
keytool -list -keystore xxx.keystore
eg:查看debug.keystore
keytool -list -keystore ~/.android/debug.keystore
254. mac 命令行安装软件
通过brew安装,相当于ubuntu中得apt-get
首先安装brew
curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local –strip 1
然后就可以使用brew安装软件了
比如 使用brew安装软件 brew install wget
255.代码混淆时 报如下错误 Error:Execution failed for task ‘:app:proguarxxxRelease’.
java.io.IOException: Can’t read [/libs/xxx.jar] (No such file or directory)
http://stackoverflow.com/questions/26028171/android-studio-proguard-java-io-ioexception-bin-classes-no-such-file-or-d
解答 proguard-android.txt文件中不用在指定 -injars, -outjars, or -libraryjars or libs.
The Android Gradle plugin already specifies all input and output for you, so you must not specify -injars, -outjars, or -libraryjars.
Moreover, the file proguard-android.txt in the Android SDK specifies all generic Android settings for you, so you shouldn’t specify them again.
Essentially, your file proguard-rules.txt can be empty, except for any application-specific settings to make sure any reflection continues to work
256.Android中如何设置RadioButton在文字的右边,图标在左边
解决方法 :
第一步:
android:button=”@null”这条语句将原来系统的RadioButton图标给隐藏起来。
第二步:
android:drawableRight=”@android:drawable/btn_radio”这条语句
参考 http://blog.csdn.net/sunnyfans/article/details/7901592
257.java报“非法字符: \65279 ”错误的解决方法
众所周知,在跨程序的工程中,统一编码是至关重要的