错误解决:android.view.InflateException: Binary XML file line #11: Error inflating class com.tony.timepicker.TimePicker
今天在做项目开发时遇到这么一个错误,完整的错误提示信息如下:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tony.timepicker/com.tony.timepicker.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class com.tony.timepicker.TimePicker
com.tony.timepicker.TimePicker类为一个自定义View类,内容如下:
package com.tony.timepicker; import java.util.Calendar; import android.content.Context;
import android.text.format.DateFormat;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.NumberPicker;
import android.widget.NumberPicker.OnValueChangeListener; public class TimePicker extends FrameLayout {
private NumberPicker mHourSpinner;
private NumberPicker mMinuteSpinner;
private Calendar mDate;
private int mHour, mMinute;
private String[] mDateDisplayValues = new String[7];
private OnTimeChangedListener mOnTimeChangedListener; public TimePicker(Context context) {
super(context);
init(context);
} public void init(Context context) {
mDate = Calendar.getInstance();
// android.widget.TimePicker
mHour = mDate.get(Calendar.HOUR_OF_DAY);
mMinute = mDate.get(Calendar.MINUTE); inflate(context, R.layout.time_picker, this); updateTimeControl(); mHourSpinner = (NumberPicker) this.findViewById(R.id.np_hour);
mHourSpinner.setMaxValue(23);
mHourSpinner.setMinValue(0);
mHourSpinner.setValue(mHour);
mHourSpinner.setOnValueChangedListener(mOnHourChangedListener); mMinuteSpinner = (NumberPicker) this.findViewById(R.id.np_minute);
mMinuteSpinner.setMaxValue(59);
mMinuteSpinner.setMinValue(0);
mMinuteSpinner.setValue(mMinute);
mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener);
} private NumberPicker.OnValueChangeListener mOnDateChangedListener = new OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mDate.add(Calendar.DAY_OF_MONTH, newVal - oldVal);
updateTimeControl();
onTimeChanged();
}
}; private NumberPicker.OnValueChangeListener mOnHourChangedListener = new OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mHour = mHourSpinner.getValue();
onTimeChanged();
}
}; private NumberPicker.OnValueChangeListener mOnMinuteChangedListener = new OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mMinute = mMinuteSpinner.getValue();
onTimeChanged();
}
}; private void updateTimeControl() {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(mDate.getTimeInMillis());
cal.add(Calendar.DAY_OF_YEAR, -7 / 2 - 1);
for (int i = 0; i < 7; ++i) {
cal.add(Calendar.DAY_OF_YEAR, 1);
mDateDisplayValues[i] = (String) DateFormat.format("MM.dd EEEE",
cal);
}
} public interface OnTimeChangedListener {
void onTimeChanged(TimePicker view, int year, int month, int day,
int hour, int minute);
} public void setOnTimeChangedListener(OnTimeChangedListener callback) {
mOnTimeChangedListener = callback;
} private void onTimeChanged() {
if (mOnTimeChangedListener != null) {
mOnTimeChangedListener.onTimeChanged(this,
mDate.get(Calendar.YEAR), mDate.get(Calendar.MONTH),
mDate.get(Calendar.DAY_OF_MONTH), mHour, mMinute);
}
}
}
经过在网上查找相关问题,找到问题的原因:
因为com.tony.timepicker.TimePicker类没有定义另外两个构造函数TimePicker(Context context, AttributeSet attrs)和TimePicker(Context context, AttributeSet attrs, int defStyle)导致的错误。
解决办法:
定义构造函数TimePicker(Context context, AttributeSet attrs)和TimePicker(Context context, AttributeSet attrs, int defStyle)。
错误解决:android.view.InflateException: Binary XML file line #11: Error inflating class com.tony.timepicker.TimePicker的更多相关文章
- Android项目部署时,发生AndroidRuntime:android.view.InflateException: Binary XML file line #168: Error inflating class错误
这个错误也是让我纠结了一天,当时写的项目在安卓虚拟机上运行都很正常,于是当我部署到安卓手机上时,点击登陆按钮跳转到用户主界面的时候直接结束运行返回登陆界面. 当时,我仔细检查了一下自己的代码,并 ...
- bug_ _ android.view.InflateException: Binary XML file line #2: Error inflating class <unknown
========= 5.0 android异常“android.view.InflateException: Binary XML file line # : Error inflating ...
- widget自定义控件【android.view.InflateException: Binary XML file line #2: Error inflating class...】
此错误比较难定位,场景是这样的:在一个widget中使用了自定义控件,始终会报 android.view.InflateException: Binary XML file line #2: Erro ...
- Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.design.widget.TabLayout,TableLayout引起页面崩溃
在使用TableLayout的时候,运行引用程序直接Crash. FATAL EXCEPTION: main Process: com.edaixi.activity, PID: 9703 java. ...
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ex.activity/com.ex.activity.LoginActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ex.activity/com.ex.activity.L ...
- TextInputLayout低版本bug :“android.view.InflateException: Binary XML file line #6 : Error inflating class Textview”
开发中用到TextInputLayout配合TextInputEdittext做输入框,在android7.0 android8.0手机上运行正常,在异步android5.0.2的手机上,点击输入框就 ...
- android.view.InflateException: Binary XML file line #34: Error inflating class
问题一般出在xml的第三方View的全类名,你可能是直接粘贴过来的,没有改成自己项目的全类名.
- 【Android开发实践】android.view.InflateException: Binary XML file line #12: Error inflating class fragment问题解决
一般出现的原因是fragment引入的包错了,应该是import android.app.ListFragment;而不是import android.support.v4.app.ListFragm ...
- Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.sup
解决:找不到资源文件: 系统会根据分辨率来选择加载不同drawable下文件夹的资源,如果只在一个文件下放了资源文件,不同的分辨率设备的会报错.
随机推荐
- 用OC实现双向链表:构造链表、插入节点、删除节点、遍历节点
一.介绍 双向链表:每一个节点前后指针域都和它的上一个节点互相指向,尾节点的next指向空,首节点的pre指向空. 二.使用 注:跟单链表差不多,简单写常用的.循环链表无法形象化打印,后面也暂不实现了 ...
- 【Linux命令】文本文件编辑命令10个(cat、more、less、head、tail、tr、wc、stat、cut、diff)
目录 cat查看文档 more可分页查看文档 less相比较more功能更强大 head查看文档的前N行 tail查看文档的后N行或试试刷新查看 tr替换文本字符 wc统计文本行数 stat查看文档存 ...
- 层级轮播图(animate)
层级轮播图(animate) css <style type="text/css"> * { margin: 0; padding: 0; } ul, ol { lis ...
- go语言中map每次遍历的顺序不同-问题分析
WHAT? 发现下面这段代码,多次运行出的结果是不一样的 mapper := make(map[int]string) mapper[1] = "1" mapper[2] = &q ...
- 微信网站登录doem
直接上代码 namespace CloudPrj.WeiXin { public partial class index : System.Web.UI.Page { ...
- c#微信公众号开发一----基本设置,服务器配置token验证,获取timestamp/nonce/signature
一.c#微信公众号开发----基本设置 参考微信官方文档 https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Acce ...
- Python笔记:设计模式之命令模式
命令模式,正如模式的名字一样,该模式中的不同操作都可以当做不同的命令来执行,可以使用队列来执行一系列的命令,也可以单独执行某个命令.该模式重点是将不同的操作封装为不同的命令对象,将操作的调用者与执行者 ...
- centOS服务器基本命令
1.卸载/安装mySQL:(因为我是该服务器的管理员,所以这些命令都不用在前面加sudo) yum remove mysqlyum install mysql 2.进入根目录 cd / 3.查看cen ...
- 多线程学习三:Thread API,ThreadLocal,synchronized,volatile和Condition
一.Thread API: setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh) 首先要了解什么是Thread. ...
- SpringMVC学习笔记一(请求流程和配置,启动项目)
springmvc请求流程: 1.用户发送请求至前端控制器DispatcherServlet 2.DispatcherServlet收到请求调用HandlerMapping处理器映射器. 3.处理器映 ...