java.lang.NumberFormatException: Invalid float
2015-07-14 17:14
756 查看
java.lang.NumberFormatException: Invalid float: "30.0dp"错误
原因:attrs.xml如下
<declare-styleable name="Title">
<attr name="titles" format="string" />
<attr name="titlecolor" format="color" />
<attr name="titlesize" format="dimension" />
<attr name="leftBackground" format="reference|color" />
<attr name="rightBackground" format="reference|color" />
</declare-styleable>
layout文件:<hy.mingancai.tongqutang.view.ActivityTitles
android:id="@+id/childstar_msg_title_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/lanse"
android:padding="5dp"
title:rightBackground="@drawable/map"
title:titlecolor="@color/white"
title:titles="我的"
title:titlesize="10dp" >
</hy.mingancai.tongqutang.view.ActivityTitles>
自定义文件
TypedArray ta = context
.obtainStyledAttributes(attrs, R.styleable.Title);
float titleSize = ta.getFloat(R.styleable.Title_titlesize, 0);
错误就处在ta.getFloat这个方法中,因为attr文件中titlesize属性的参数类型是dimension,So ,正确的写法是:
float titleSize = ta.getDimension(R.styleable.Title_titlesize, 0);
原因:attrs.xml如下
<declare-styleable name="Title">
<attr name="titles" format="string" />
<attr name="titlecolor" format="color" />
<attr name="titlesize" format="dimension" />
<attr name="leftBackground" format="reference|color" />
<attr name="rightBackground" format="reference|color" />
</declare-styleable>
layout文件:<hy.mingancai.tongqutang.view.ActivityTitles
android:id="@+id/childstar_msg_title_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/lanse"
android:padding="5dp"
title:rightBackground="@drawable/map"
title:titlecolor="@color/white"
title:titles="我的"
title:titlesize="10dp" >
</hy.mingancai.tongqutang.view.ActivityTitles>
自定义文件
TypedArray ta = context
.obtainStyledAttributes(attrs, R.styleable.Title);
float titleSize = ta.getFloat(R.styleable.Title_titlesize, 0);
错误就处在ta.getFloat这个方法中,因为attr文件中titlesize属性的参数类型是dimension,So ,正确的写法是:
float titleSize = ta.getDimension(R.styleable.Title_titlesize, 0);
相关文章推荐
- Java日期格式化及其使用例子收集
- Android开发Eclipse中的键盘快捷键
- Spring CommonsMultipartResolver 上传文件
- JSP上传视频后自动转成flv的核心JAVA方法
- 标准JavaBean规范
- 用java程序调用ffmpeg执行视频文件格式转换flv
- 两个办法帮你解决如何在Java中产生随机数
- java的native关键字
- struts2的session取不到值,已经解决,做个记录
- java final关键字的用法
- JAVA对象转为Java String的几种常用方法
- spring IOC 集合collections注入
- java变量类型及注释
- Spring2.5+Struts1.+Hibernate3.3完美整合
- 解决spring mvc 乱码问题
- Google Java编程风格指南中文版
- 【j2ee spring】43、巴巴运动网添加,编辑,上架,下架产品样式
- sas与java关于运算的一些转换
- 【Java】给定两个32位的整数N与M,以及表示比特位置的i与j。编写一个方法,将M插入N,使得M从N的第 j 位开始,到第 i 位结束。
- spring Bean范围scope=singleton或prototype