Android little error records
1:在清单文件(Manifest)中加入权限时要注意,如下例:
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
而非:
<uses-permission
android:name="android.permission.CHANGE_NETWORK_STATE"
android:name="android.permission.CHANGE_WIFI_STATE"/>
写成后一种情况将会报如下错误:
已经为元素 "uses-permission" 指定绑定到名称空间 "http://schemas.android.com/apk/res/android" 的属性 "name"。
2:Replace "..." with ellipsis character (…, &&;#8230;) ?
按照提示即可解决,提示的意思即为,用省略号的字符形式(…, &&;#8230;)?替换省略号"..."(这个省略号是由英文状态下输入的三个圆点),其中(…, &&;#8230;)?貌似是一个正则表达式(本人不太确定),解决方法有两个:
第一种方法:跳到中文输入法下,按shift+^打出省略号
第二种方法:直接将省略号替换为【…】
猜测原因:可能是在字符编码的情况下,省略号可以更好的显示吧
3:这里记录的只能算是一个小小的经验,不知道有时候你遇到过这样的问题没有,当你引用一个drawable资源,比如图片资源时,你引用后系统报错,说找不到这样的资源,而且有时候你即使把你的图片重命名了也不行,这个时候建议你仔细检查你的图片名称,有时候在图片的名称里面会偶然加入一些空格,英文状态下的空格有时候你不细心去看,还真的难以发现那么一个小小的空格,但是可能这个空格就会一直导致你的编译器给你报错。遇到了这种情况,如果确保了你的命名格式对的话,希望你可以仔细检查一下名字,看看有没有写错。
4:ADT警告:This tag and its children can be replaced by one <TextView/> and a compound drawable
以一个例子呈现:
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="10dp"
- android:padding="5dp" >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="My Compound Button" />
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/my_drawable" />
- </LinearLayout>
- <TextView
- android:layout_marginTop="10dp"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="My Compound Button"
- android:drawableRight="@drawable/my_drawable" android:padding="5dp" />
但有时候,我们或许在一个<Linearlayout>中设置<TextView> <ImageView>另有他用。一个很好的修改方法就是将<Linearlayout>修改为<RelativeLayout>布局,其次对于 android:drawableRight属性不可以使用,否则将会抛出另一个异常:Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path),因为这个属性对象是drawable。
下面是一个示例:
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <ImageView
- android:id="@+id/image"
- android:contentDescription="@string/cs"
- android:layout_width="90dip"
- android:layout_height="90dip"
- />
- <TextView
- android:id="@+id/title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@id/image"/>
- </RelativeLayout>
5:Eclipse警告:Warning:ArrayList is a raw type. References to generic type ArrayList should be parameterized 解决方案超赞(暂未翻译),参见:http://www.cnblogs.com/killerlegend/p/3349663.html
6:textview cannot be cast to imageview........
可以尝试的解决方法:Project-->clean,然后重新启动一次程序。
7:
Android之 ListView 的setonItemSelectedListener()之item单元点击无效处理方法
可以考虑换成下面的解决方法:
- mListView.setOnItemClickListener(new OnItemClickListener()
- {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position,long id)
- {
- Toast.makeText(getApplicationContext(),
- "当前所在行为:"+Long.toString(parent.getItemIdAtPosition(position)+1),
- Toast.LENGTH_SHORT).show();
- }
- });
模拟器的鼠标滚动时会触发setItemOnselected()事件,而真机使用的软件,应该用 setItemOnClick().即手指头点击屏幕所出发的事件。
8:Error:ScrollView can host only one direct child.......
意思就是ScrollView中只能有一个直接子代,如果出现两个或者两个以上,那么久会出现错误。你将scrollview中的子代换成一个就解决问题了。
9:AlertDialog提示错误:android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
原因:在使用AlertDialog的时候,如下:
Dialog dialog = new AlertDialog.Builder(context).
setTitle("温馨提示").
setIcon(R.drawable.image).
setMessage("本应用目前仅支持xxx地区,谢谢您的支持!").create();
dialog.show();
出错原因在于AlertDialog.Builder(context)中传入的参数context不正确,传入的context不能由getApplicationContext()获得,而必须是Activity的名字,如果你的Activity的类的名字是Home.java
那么你在传入context的时候,只需传入Home.this即可。
10:报错:
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
在Intent变量中声明FLAG_ACTIVITY_NEW_TASK
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Android little error records的更多相关文章
- android studio Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
android studio Error:java.lang.OutOfMemoryError: GC overhead limit exceeded 在app下的build.gradle中找到and ...
- android stack error message is Fail to start the plugin
E: 08-26 16:34:11.934: E/AliSDK(32236): 错误编码 = 1002208-26 16:34:11.934: E/AliSDK(32236): 错误消息 = SDK ...
- android studio error configuration with name default not found
Android Studio报错: android studio error configuration with name default not found 在进行sync的时候,提示Error: ...
- [2015-06-10 20:53:50 - Android SDK] Error when loading the SDK:
1.错误描述 [2015-06-10 20:53:50 - Android SDK] Error when loading the SDK: Error: Error parsing D:\Andro ...
- Android Build Error(1)
Type 1 —— Build Path Problem : **.jar包文件缺失 1.在Android项目根目录下新建一个libs文件夹: 2.把你需要的导入的第三方Jar包复制进这个目录: 3. ...
- 打包Android:Error building Player: CommandInvokationFailure
错误log Error building Player: CommandInvokationFailure: Unable to determine the tools version of the ...
- android学习——error opening trace file: No such file or directory (2)
1.疑惑: 程序运行起来的时候日志总是显示下面这个错误,但是不影响程序的正常进行,我是用真机来测试的,android4.4.4(API17). 02-11 14:55:03.629 15525-155 ...
- 关于 Android项目“error: Apostrophe not preceded by \ (”的解决方法
用Eclipse环境开发Android项目,如果编译时控制台报出“error: Apostrophe not preceded by \ (”这种错误,那么多半是因为项目中的一个strings.xml ...
- [转]如何解决:Android中 Error generating final archive: Debug Certificate expired on 10/09/18 16:30 的错误
本文转自:http://www.cnblogs.com/yyangblog/archive/2011/01/07/1929657.html 问题概述: 在导入一个app后提示如下错误: “Error ...
随机推荐
- 控制反转(IoC)
大量使用工厂模式引起的问题: Client 对象需要使用 Service1 的 execute( ) 方法完成特定功能,而 Service1 的实现 Service1Impe类 ...
- 11. Android框架和工具之 Logger(调试代码)
1. Logger Logger是android是一个简单.漂亮.功能强大的Android日志程序. 日志程序提供了 : 线程信息Thread information 类信息Class informa ...
- 沈逸老师PHP魔鬼特训笔记(8)
创建模板文件: 这节课老师带领我们开始创建TEMPLATE,按照老师教导的思路,我们希望这样一种代码写法:1.譬如我定义一个变量$name=‘’;2.然后呢我读取一个模板.3.再然后我在这个模板里 设 ...
- .net重启iis线程池和iis站点程序代码分享
重启站点: /// <summary> /// 根据名字重启站点.(没重启线程池) /// </summary> /// <param name="sitena ...
- 【Shell脚本学习20】Shell until循环
until 循环执行一系列命令直至条件为 true 时停止.until 循环与 while 循环在处理方式上刚好相反.一般while循环优于until循环,但在某些时候,也只是极少数情况下,until ...
- 【MongoDB】MongoDB服务器搭建(Unix/Linux)
1.安装MongboDB安装包(开源免费的哟) 在Mac 下 brew install mongoDB 就可以啦 安装要等一会儿,大概200M 2. cd到MongboDB文件夹 - 如果是用home ...
- php 短信网关短信内容不能有空格
最近在做一个短信通知功能,接口参数都按文档写好了,就是不能发送短信,查了半天,原来是短信内容有空格,之前短信用的英文标点符号,符号后都有一个空格,用了date('Y-m-d H,i,s')函数,后来把 ...
- hdu 3585 二分+最大团
题目:给出平面上n个点,现在找m个点,并且使得这m个点最近的两个最远. 分析:显然这满足二分的性质,二分答案,根据点距离需要大于等于二分值重新构造新图,则问题变成了:在新图中找出满足所有点对之间的距离 ...
- C# 新特性 dynamic的使用及扩展
个人而言感觉C#的dynamic是一个特别实用的东西,为日常开发工作中的封装,数据传递等带来了很高的可扩展性. C#4.0中通过对数据类型后期绑定的支持,演化出了dynamic.任何直接声明为这种类型 ...
- C#常用的字符串操作, 包括截取
1.取字符串的前i个字符 (1)string str1=str.Substring(0,i); (2)string str1=str.Remove(i,str.Length-i); 2.去掉字符串的前 ...