Android 测试项目中 ImageView 扩展在构建时崩溃
我正在尝试测试我创建的扩展 ImageView 的类。它在构造时崩溃了,显然是在运行任何代码之前(使用调试器单步调试没有到达构造代码中的任何断点)。作为健全性检查,我创建了这个类:
package com.blah.thing;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
public class DoNothing extends ImageView {
public DoNothing(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public DoNothing(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public DoNothing(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
}
它仍然崩溃。我从一个 Activity 中调用它,该 Activity 基本上什么也不做(到目前为止):
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Context context = getApplicationContext();
DoNothing dn = new DoNothing(context);
setContentView(R.layout.main);
}
该 Activity 位于主项目旁边的 Android 测试项目中......我需要做些什么来修复依赖项或其他东西吗?顺便说一句,我正在导入所有需要引用 DoNothing、Context 等的包。
谢谢!
I am trying to test a class I have created that extends ImageView. It crashed on construction, apparently before running any code (stepping through with the debugger didn't reach any breakpoints in the construction code). As a sanity check I created this class:
package com.blah.thing;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
public class DoNothing extends ImageView {
public DoNothing(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public DoNothing(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public DoNothing(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
}
It STILL crashes. I am calling it from an Activity which also basically does nothing (so far):
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Context context = getApplicationContext();
DoNothing dn = new DoNothing(context);
setContentView(R.layout.main);
}
This activity is in an Android test project alongside the main project ... is there something I need to do to fix the dependencies or something? By the way I am importing all the packages I need to refer to DoNothing, Context and so on.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
而不是
onCreate(...)
try to use
instead of
on onCreate(...)