自定义View编译失败Binary XML file line #255: Error inflating

02-2815:17:16.281:DEBUG/AndroidRuntime(391):ShuttingdownVM
02-2815:17:16.281:WARN/dalvikvm(391):threadid=1:threadexitingwithuncaughtexception(group=0x4001d800)
02-2815:17:16.372:ERROR/AndroidRuntime(391):FATALEXCEPTION:main
02-2815:17:16.372:ERROR/AndroidRuntime(391):java.lang.RuntimeException:UnabletostartactivityComponentInfo{com.min.musicdemo/com.min.musicdemo.MusicDemo}:android.view.InflateException:BinaryXMLfileline#255:Errorinflatingclasscom.min.musicdemo.lyric.LyricView
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.app.ActivityThread.access$2300(ActivityThread.java:125)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.os.Handler.dispatchMessage(Handler.java:99)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.os.Looper.loop(Looper.java:123)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.app.ActivityThread.main(ActivityThread.java:4627)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atjava.lang.reflect.Method.invokeNative(NativeMethod)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atjava.lang.reflect.Method.invoke(Method.java:521)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atcom.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atdalvik.system.NativeStart.main(NativeMethod)
02-2815:17:16.372:ERROR/AndroidRuntime(391):Causedby:android.view.InflateException:BinaryXMLfileline#255:Errorinflatingclasscom.min.musicdemo.lyric.LyricView
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.view.LayoutInflater.createView(LayoutInflater.java:513)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.view.LayoutInflater.rInflate(LayoutInflater.java:618)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.view.LayoutInflater.rInflate(LayoutInflater.java:621)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.view.LayoutInflater.inflate(LayoutInflater.java:407)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atcom.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.app.Activity.setContentView(Activity.java:1647)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atcom.min.musicdemo.MusicDemo.onCreate(MusicDemo.java:255)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-2815:17:16.372:ERROR/AndroidRuntime(391):...11more
02-2815:17:16.372:ERROR/AndroidRuntime(391):Causedby:java.lang.reflect.InvocationTargetException
02-2815:17:16.372:ERROR/AndroidRuntime(391):atcom.min.musicdemo.lyric.LyricView.<init>(LyricView.java:39)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atjava.lang.reflect.Constructor.constructNative(NativeMethod)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atjava.lang.reflect.Constructor.newInstance(Constructor.java:446)
02-2815:17:16.372:ERROR/AndroidRuntime(391):atandroid.view.LayoutInflater.createView(LayoutInflater.java:500)
02-2815:17:16.372:ERROR/AndroidRuntime(391):...23more
02-2815:17:16.372:ERROR/AndroidRuntime(391):Causedby:java.lang.NullPointerException
02-2815:17:16.372:ERROR/AndroidRuntime(391):...27more
02-2815:17:16.421:WARN/ActivityManager(60):Forcefinishingactivitycom.min.musicdemo/.MusicDemo
02-2815:17:16.942:WARN/ActivityManager(60):ActivitypausetimeoutforHistoryRecord{44035078com.min.musicdemo/.MusicDemo}
02-2815:17:27.986:WARN/ActivityManager(60):ActivitydestroytimeoutforHistoryRecord{44035078com.min.musicdemo/.MusicDemo}
02-2815:21:17.266:DEBUG/SntpClient(60):requesttimefailed:java.net.SocketException:Addressfamilynotsupportedbyprotocol

xml中使用
XML/HTML code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!--VIEW3*********lyricarea-->
< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:id "@+id/llLyric"
android:orientation "vertical"
android:layout_width "fill_parent"
android:layout_height "fill_parent"
android:visibility "gone"
android:layout_weight "1"
>
TextView
"@+id/tvLyricTitle"
"fill_parent"
"wrap_content"
android:paddingLeft "4dip"
android:text "动感歌词"
android:textColor "#0000FF"
android:layout_gravity "center_horizontal"
android:gravity "center"
/>
com.min.musicdemo.lyric.LyricView
"@+id/lyricView"
"fill_parent"
"200dip"
/>
</ LinearLayout >

类定义
Java code
?
25
26
27
28
29
30
31
32
33
34
public class LyricView extends View{
private static final StringTAG= "LyricView" ;
private Paintpaint;
Rectrect; //歌词显示区域
List<Sentence>list= null ; //歌词list
Stringtext= "Lyricisloading..." //单行歌词
long currentTime= 0 //正在演唱的时间
int color= 0xFF0000FF //歌词颜色
public LyricView(Contextcontext){
super (context);
//生成paint
paint= new Paint();
rect.left= this .getLeft();
rect.top= .getTop();
rect.right= .getRight();
rect.bottom= .getBottom();
}
LyricView(Contextcontext,AttributeSetattrs){ //构造方法;根据需要实现继承自View的方法
(context,attrs);
//生成paint
Paint();
rect.left= 10 ;
rect.top= 50 ;
rect.right= ;
rect.bottom= ;
//对于我们自定义的类中,我们需要使用一个名为obtainStyledAttributes的方法来获取我们的定义。
//得到自定义控件的属性值。
}

靠,原来是在构造函数中忘了创建rect对象
加上rect=newRect();就ok了

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类
XML入门的常见问题(二)
Java对象的强、软、弱和虚引用
JS解析XML文件和XML字符串详解
java中枚举的详细使用介绍
了解Xml格式
XML入门的常见问题(四)
深入SQLite多线程的使用总结详解
PlayFramework完整实现一个APP(一)
XML和YAML的使用方法
XML轻松学习总节篇