InstantiationException,newInstance失败:没有,而Activity中只有默认构造函数

发布于 2024-10-17 03:32:27 字数 1113 浏览 4 评论 0原文

我们在创建 Activity 实例时收到了 InstantiationException 的堆栈跟踪。 日志有 newInstance failed: no() 消息

情况非常清楚:VM 找不到默认的无参数构造函数。 此线程对此进行了解释,

正如我的研究表明,人们在向构造函数添加参数时通常会收到此消息他们的活动,这绝对是糟糕的。但这不是我们的情况 - 我们总是可以访问默认构造函数。 该异常的另一个原因可能是初始化某些成员时的另一个异常(初始化在默认构造函数中运行,对吗?) - 但我们同样不这样做。所有成员均在 onCreate() 方法中初始化。

一些细节(名称已更改): Activity 添加到 AndroidManifest.xml:

<manifest
    package="app.name"
    ....>
    ....
    <activity
        android:name="app.name.activity.OurActivity"
        android:label="@string/NAME">
    </activity>

现在我们创建意图的方式可能看起来很奇怪,但它在每种情况下都有效:

Context packageContext = layoutInflater.getContext().createPackageContext("app.name", 0);
Intent intent = new Intent(packageContext, OurActivity.class);
...startActivity(intent);

我认为这可能是一个问题,但是: 1)这可以正常工作几个月 2)同一客户端在另一个开始使用活动作为上下文的活动中遇到相同的异常;

我无法重现异常来理解/修复它。但不知怎的,我们的一位客户得到了它。他有 Droid ERIS(Verizon) 设备

有什么想法吗?有没有什么情况我不知道VM什么时候找不到默认构造函数?

We received stack trace of InstantiationException while creating instance of Activity.
Log has newInstance failed: no <init>() message

The situation is quite clear: VM can't find default parameterless constructor. This is explained in this thread

As my research shown people usually receive this when they add parameters to constructors of their Activities, which definitely is bad. But this is not our case - we always have access to default constructor.
Another reason of that exception could be another exception while initializing some member(initialiation is run in default constructor, right?) - but again we don't do that. All members are initialized in onCreate() method.

Some details(names changed):
activity is added to AndroidManifest.xml:

<manifest
    package="app.name"
    ....>
    ....
    <activity
        android:name="app.name.activity.OurActivity"
        android:label="@string/NAME">
    </activity>

Now the way that we create the intent may look strange, but it works in every case:

Context packageContext = layoutInflater.getContext().createPackageContext("app.name", 0);
Intent intent = new Intent(packageContext, OurActivity.class);
...startActivity(intent);

I would think that this could be a problem, but:
1) this works fine for months
2) same client got same exception in another activity which is start using activity as a context;

I can't reproduce the exception to understand/fix it. But somehow one of our clients got it. He has Droid ERIS(Verizon) device

Any thoughts? Is there any case I don't know about when VM will not find the default constructor?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文