例外,当我从Eclipse运行我的应用程序 [英] Exception when I run my application from Eclipse

查看:150
本文介绍了例外,当我从Eclipse运行我的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直有这个问题,近2个月了,不能弄明白。现在的问题是,如果我的应用程序正在运行,我跑(重新安装)从Eclipse中我的应用程序,我得到这说明我的应用程序崩溃的错误消息不幸的是,已经停止了。。我注意到,当我运行它离我的电脑/ Eclipse中,它也发生,我认为这仅发生后,我不跑了一段时间。

I've been having this problem for almost 2 months now and can't figure it out. The problem is that if my application is running and I run (reinstall) my application from Eclipse, I get an error message indicating that my application has crashed 'Unfortunately, has stopped.'. I notice that it also occurs when I run it away from my PC/Eclipse, I think that it happens only after I don't run it for a while.

这只会发生,如果应用程序是活跃在第三活动(BaseDiagramActivity <$ C C $>),然后我再从Eclipse中运行的应用程序。我已经剥离出来基本上所有的应用程序不同的是3活动,它仍然发生。

It only occurs if the app is active in the 3rd activity (BaseDiagramActivity) and then I run the app again from Eclipse. I've stripped out basically all the application except the 3 activities and It's still happening.

我找啊找为解​​决这个问题,但找不到任何好的答案或者一个适用于我。

I've searched and searched for a solution to this problem but can't find any good answer or one that applies to me.

它似乎并不像一个硬件或Android版本的问题,因为我对我的平板电脑(4.0.3),我的手机上运行这个(4.0.2,是发生在4.0.1更新之前)。当然,除非它是一个冰激凌三明治的bug。

It doesn't seem like a hardware or android version issue as I'm running this on my tablet (4.0.3) and my phone (4.0.2, was happening on 4.0.1 before update). Unless of course it is an ice cream sandwich bug.

让我知道是否需要任何更多的信息。

Let me know if any more info is required.

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
   at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3938)
   at android.app.ActivityThread.access$1300(ActivityThread.java:123)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4424)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
   at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
   at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:362)
   at android.app.LoadedApk.getClassLoader(LoadedApk.java:305)
   at android.app.LoadedApk.makeApplication(LoadedApk.java:474)
   ... 11 more

Android的code

<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.0.1_r1/android/app/LoadedApk.java?av=f#342">LoadedApk.initializeJavaContextClassLoader() - 线路362似乎是罪犯

The Android Code

LoadedApk.initializeJavaContextClassLoader() - Line 362 seems to be the offender

下面是相关文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="[my package]"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="14" />

    <application 
        android:icon="@drawable/ic_launcher" 
        android:label="@string/app_name" >
        <activity 
            android:name="HomeActivity" 
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="LoadDiagramActivity" android:label="Load Diagram"></activity>
        <activity android:name="BaseDiagramActivity" android:label="Base Diagram"></activity>
    </application>

</manifest>

HomeActivity.java

public class HomeActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.home);

        Button diagramButton = (Button)findViewById(R.id.diagram);
        diagramButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(HomeActivity.this, LoadDiagramActivity.class));
            }
        });
    }
}

LoadDiagramActivity.java

public class LoadDiagramActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.load_diagram_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
            case R.id.add_new_diagram:
                startActivity(new Intent(this, BaseDiagramActivity.class));
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}

BaseDiagramActivity.java

实际上它并不不管是什么活动,这是,只要是第三方活动开始出现异常(或点击 LoadDiagramActivity 添加按钮。

public class BaseDiagramActivity extends Activity {
}

home.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/diagram"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Diagram" />

</LinearLayout>

更多信息

当我为了问一个简单的答案剥离下来我的项目,我把一切都变成了包的命名空间。在实际的项目中有5个名字空间,他们仍然present当我测试的精简版不过才不叫(据我可以看到)。

Additional information

When I stripped down my project in order to ask a simpler answer, I moved everything into the package's namespace. In the actual project there are 5 namespaces, they were still present when I was testing with the stripped down version however just not called (as far as I could see).

下面是包:

  • [包装] - 通用逻辑
  • [包装] .activities - 所有活动和基本活动
  • [包装] .database - 与数据库的所有交互
  • [包装] .models - 用于保存/载入数据模型
  • [包装] .renderables - 画在画布对象
  • [package] - general logic
  • [package].activities - all activities and base activities
  • [package].database - all interaction with the database
  • [package].models - models for saving/loading data
  • [package].renderables - objects drawn to a canvas

我尝试添加一个'机器人:sharedUserId'属性的清单和,似乎什么都不做两次我试过了。当我开始研究这个,我来到了共享用户ID只适用于不同的项目,而不是不同的包的结论。

I have tried to add an `android:sharedUserId' attribute to the manifest and and it seemed to do nothing both times I tried. When I was initially investigating this I came to the conclusion that the shared user id only applied to different projects, not different packages.

此外,我不相信有与数据库交互的任何时候我都剥离下来。该活动的第三个可能是任何活动,甚至HomeActivity,事实是一些反对这一理论。

Also I don't believe there was any interaction with the database when I stripped everything down. The fact that the 3rd activity could be any activity, even HomeActivity, was something against this theory.

  • <一个href="http://stackoverflow.com/questions/9039017/android-app-application-cannot-be-instantiated-due-to-nullpointerexception">stackoverflow: android.app.Application不能因NullPointerException异常
  • 实例
  • <一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.0.1_r1/android/app/LoadedApk.java?av=f">Greo$c$c android.app.LoadedApk在4.0.1
  • 可能的竞争状态?
  • <一个href="http://$c$c.google.com/p/android/issues/detail?id=25869&can=1&q=LoadedApk.makeApplication&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars">Android问题#25869
  • stackoverflow: android.app.Application cannot be instantiated due to NullPointerException
  • GreoCode android.app.LoadedApk on 4.0.1
  • Possible race condition?
  • Android issue #25869

我已经跳了回来到这个项目最后几天,我在Eclipse朱诺创造了一个全新的项目(是在太阳神前)和转移​​所有手动过这样处理的Eclipse和Android工具,几乎所有的清单互动,但它仍然存在。我会看它多一点,在未来的几天和更新,如果我发现任何东西。

Last couple of days I've jumped back into this project, I created a brand new project in Eclipse Juno (was on Helios before) and transferred everything over manually so that Eclipse and Android tools handled almost all of the Manifest interaction but it's still occurring. I will look at it a bit more over the next few days and update if I find anything.

仅供参考我的新项目瞄准的是以下内容:

FYI my new project is targeting the following:

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="15" />

新项目结构也有根包中的所有活动,现在(即[包装],不是[包装] .activities)。我还使用了(新的?)语法显示父活动:

The new project structure also has all the activities in the root package now (ie. [package], not [package].activities). I'm also using the (new?) syntax to show the parent activity:

<meta-data
    android:name="android.support.PARENT_ACTIVITY"
    android:value="[my package].LoadDiagramActivity" />

它也仍然发生在我现在更新Galaxy Nexus的运行杰利贝恩4.1.2。

It is also still occurring on my now updated Galaxy Nexus running Jellybean 4.1.2.

推荐答案

尝试在清单文件中添加一件事,我相信你已经尝试过。

Try adding one more thing in Manifest file, I am sure you have already tried..

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="[my package]" 
    android:versionCode="1" 
    android:versionName="1.0"
    android:sharedUserId="com.mj.app" > 

这似乎是在你的项目中有多个包,如 com.package.p1,com.package.p2,com.package.p3 ..

和同时启动你的 P1 ,然后移动到 P2 - P3 ... 在那个时候,你尝试运行它again..so在Android为您提供了错误。

And while starting you are in p1 and then moves on to p2 - p3... and at that time you try to run it again..so the Android gives you error.

这篇关于例外,当我从Eclipse运行我的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆