Android 测试项目中 ImageView 扩展在构建时崩溃

发布于 2024-11-17 20:32:44 字数 1181 浏览 3 评论 0原文

我正在尝试测试我创建的扩展 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮筵 2024-11-24 20:32:44

尝试使用

DoNothing dn = new DoNothing(this); 

而不是

Context context = getApplicationContext();         
DoNothing dn = new DoNothing(context); 

onCreate(...)

try to use

DoNothing dn = new DoNothing(this); 

instead of

Context context = getApplicationContext();         
DoNothing dn = new DoNothing(context); 

on onCreate(...)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文