自定义View编译失败。Binary XML file line #255: Error inflating
02-28 15:17:16.281: DEBUG/AndroidRuntime(391): Shutting down VM
02-28 15:17:16.281: WARN/dalvikvm(391): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): FATAL EXCEPTION: main
02-28 15:17:16.372: ERROR/AndroidRuntime(391): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.min.musicdemo/com.min.musicdemo.MusicDemo}: android.view.InflateException: Binary XML file line #255: Error inflating class com.min.musicdemo.lyric.LyricView
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.os.Handler.dispatchMessage(Handler.java:99)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.os.Looper.loop(Looper.java:123)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at java.lang.reflect.Method.invokeNative(Native Method)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at java.lang.reflect.Method.invoke(Method.java:521)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at dalvik.system.NativeStart.main(Native Method)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): Caused by: android.view.InflateException: Binary XML file line #255: Error inflating class com.min.musicdemo.lyric.LyricView
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.app.Activity.setContentView(Activity.java:1647)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at com.min.musicdemo.MusicDemo.onCreate(MusicDemo.java:255)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): ... 11 more
02-28 15:17:16.372: ERROR/AndroidRuntime(391): Caused by: java.lang.reflect.InvocationTargetException
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at com.min.musicdemo.lyric.LyricView.<init>(LyricView.java:39)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at java.lang.reflect.Constructor.constructNative(Native Method)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
02-28 15:17:16.372: ERROR/AndroidRuntime(391): ... 23 more
02-28 15:17:16.372: ERROR/AndroidRuntime(391): Caused by: java.lang.NullPointerException
02-28 15:17:16.372: ERROR/AndroidRuntime(391): ... 27 more
02-28 15:17:16.421: WARN/ActivityManager(60): Force finishing activity com.min.musicdemo/.MusicDemo
02-28 15:17:16.942: WARN/ActivityManager(60): Activity pause timeout for HistoryRecord{44035078 com.min.musicdemo/.MusicDemo}
02-28 15:17:27.986: WARN/ActivityManager(60): Activity destroy timeout for HistoryRecord{44035078 com.min.musicdemo/.MusicDemo}
02-28 15:21:17.266: DEBUG/SntpClient(60): request time failed: java.net.SocketException: Address family not supported by protocol
xml中使用
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 ********* lyric area -->
< 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
android:id = "@+id/tvLyricTitle"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:paddingLeft = "4dip"
android:text = "动感歌词"
android:textColor = "#0000FF"
android:layout_gravity = "center_horizontal"
android:gravity = "center"
/>
< com.min.musicdemo.lyric.LyricView
android:id = "@+id/lyricView"
android:layout_width = "fill_parent"
android:layout_height = "200dip"
/>
</ LinearLayout >
|
类定义
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
26
27
28
29
30
31
32
33
34
|
public class LyricView extends View {
private static final String TAG = "LyricView" ;
private Paint paint;
private Rect rect; // 歌词显示区域
private List<Sentence> list = null ; // 歌词list
private String text = "Lyric is loading..." ; // 单行歌词
private long currentTime = 0 ; // 正在演唱的时间
private int color = 0xFF0000FF ; // 歌词颜色
public LyricView(Context context) {
super (context);
// 生成paint
paint = new Paint();
rect.left = this .getLeft();
rect.top = this .getTop();
rect.right = this .getRight();
rect.bottom = this .getBottom();
}
public LyricView(Context context, AttributeSet attrs) { // 构造方法;根据需要实现继承自View的方法
super (context, attrs);
// 生成paint
paint = new Paint();
rect.left = 10 ;
rect.top = 50 ;
rect.right = 10 ;
rect.bottom = 50 ;
//对于我们自定义的类中,我们需要使用一个名为obtainStyledAttributes的方法来获取我们的定义。
//得到自定义控件的属性值。
}
靠,原来是在构造函数中忘了创建rect对象
|
最新文章
- linux基础命令
- JavaScript的学习资料
- Selenium 3 -how to locate the chromedriver and geckodriver place?
- 网络攻击之二:XSS(之一是SQL注入,前面有文章)
- bzoj 1914: [Usaco2010 OPen]Triangle Counting 数三角形 容斥
- android78 Fragment和Activity 传递数据
- text-overflow简单使用
- C# 程序打包
- LeetCode_Simplify Path
- Invalid embedded descriptor for ";.proto";.Dependencies passed (Protobufer)解决办法
- 安卓的UI界面开发(初学者推荐)
- 跨站数据请求哪家强——青出于蓝的jsonp
- 【转】MYSQL 使用SQLyog导入遇到问题解决
- JAVA并发编程学习笔记------FutureTask
- [HAOI 2009]逆序对数列
- Ueditor 专题
- QT之setstylesheet防止子窗体继承父窗体样式
- Windows Server 2012更新补丁后导致Micosoft ODBC for Oracle出现问题
- Django学习篇(第二部)
- 一:怎样运行python程序
热门文章
- 向mysql添加新用户并分配权限
- codeforces 645 D. Robot Rapping Results Report 二分+拓扑排序
- C#版-百度网盘API的实现(二)
- [Leetcode][Python]34: Search for a Range
- poj2578---三个数中找出第一个大于168的
- freemaker
- Qt程序设计——txt文本中获取字符串的问题
- c语言函数---M
- Boost.Asio c++ 网络编程翻译(14)
- android插件化-apkplugdemo源代码阅读指南-10