Android自定义视图导致强制关闭
我在 src > 有一个自定义视图myproject.test> HomeView
在我的主布局 xml 中,我有以下内容:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<myproject.test.HomeView
android:id="@+id/home_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</myproject.test.HomeView>
</LinearLayout>
在 HomeActivity 中,我在 onCreate 方法中进行了类似的调用。
setContentView(R.layout.main);
HomeView mHomeView = (HomeView) this.findViewById(R.id.home_view);
调用 setContentView 方法时应用程序强制关闭。看来我的主xml不正确。
有什么想法吗?
I have a custom view in src > myproject.test > HomeView
In my main layout xml I have the following:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<myproject.test.HomeView
android:id="@+id/home_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</myproject.test.HomeView>
</LinearLayout>
In the HomeActivity I have a call like this in the onCreate method.
setContentView(R.layout.main);
HomeView mHomeView = (HomeView) this.findViewById(R.id.home_view);
The app force closed when the setContentView method is called. It seems that my main xml is not correct.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的意思是它没有到达
并在它之前崩溃?
检查您的构造函数是否
需要
AttributeSet
Do you mean its not getting to the
and crashing on the line before it?
Check if your constructor is
and not
you need the AttributeSet
检查 HomeView 实现的构造函数:
Check constructors that your HomeView implements:
我的布局都没有
@+id
。也许您应该将视图设置为home_root
。与您核对R.java布局的名称,或者尝试None of my layouts have
@+id
. Maybe you should set the view tohome_root
. Check with you R.java for the name of the layout, or try