在Android中扩展Application类
我在扩展 Application 类来声明全局变量时遇到问题。我已经扩展了 Application
类,如下所示:
public class RunKeeper extends Application{
private String filename = getResources().getString(R.string.filename);
private Runner runner;
public RunKeeper(){ }
}
上面的类位于 com.tmeersschaert.android.runkeeper.domain
包中。我已经按照(我认为)应该的方式编辑了应用程序清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tmeersschaert.android.runkeeper"
android:versionCode="1"
android:versionName="1.0">
<application android:name=".domain.RunKeeper" android:icon="@drawable/icon" android:label="@string/app_name"></application>
</manifest>
问题是我在 LoadedApk.makeApplication()
方法期间不断收到“找不到源”、NullPointer 异常。
关于如何解决这个问题有什么想法吗?
I'm having troubles extending the Application class to declare global variables. I have extended the Application
class as folows:
public class RunKeeper extends Application{
private String filename = getResources().getString(R.string.filename);
private Runner runner;
public RunKeeper(){ }
}
The class above is in the com.tmeersschaert.android.runkeeper.domain
package. I have edited the application manifest as (I think) it should be:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tmeersschaert.android.runkeeper"
android:versionCode="1"
android:versionName="1.0">
<application android:name=".domain.RunKeeper" android:icon="@drawable/icon" android:label="@string/app_name"></application>
</manifest>
The problem is that I keep getting a "Source not found", NullPointer exception during the LoadedApk.makeApplication()
method.
Any thoughts on how to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你应该把这条线
放在你的构造函数中。
您是否也尝试过使用整个包名称:
I think you should put the line
in your constructor.
Have you also tried to use the whole package name:
尝试删除 .domain。来自 android:name 属性的一部分。
Try removing .domain. part from android:name property.