Android的错误了java.lang.RuntimeException [英] Android java.lang.RuntimeException error

查看:1239
本文介绍了Android的错误了java.lang.RuntimeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立我的团结Android插件。但是,当我这样做,我得到了如下的错误日志中的logcat:

  12-11 14:45:38.745:E / AndroidRuntime(26806):致命异常:主要
12-11 14:45:38.745:E / AndroidRuntime(26806):了java.lang.RuntimeException:无法实例活动ComponentInfo {com.example.marc / com.example.marc.CompassActivity}:抛出java.lang.ClassNotFoundException:没T路径上找到的类com.example.marc.CompassActivity:DexPathList [zip文件/data/app/com.example.marc-1.apk\"],nativeLibraryDirectories=[/data/app-lib/com .example.marc-1 /供应商/ lib中/系统/ lib目录]
12-11 14:45:38.745:E / AndroidRuntime(26806):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
12-11 14:45:38.745:E / AndroidRuntime(26806):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
12-11 14:45:38.745:E / AndroidRuntime(26806):在android.app.ActivityThread.access $ 600(ActivityThread.java:141)
12-11 14:45:38.745:E / AndroidRuntime(26806):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1256)
12-11 14:45:38.745:E / AndroidRuntime(26806):在android.os.Handler.dispatchMessage(Handler.java:99)
12-11 14:45:38.745:E / AndroidRuntime(26806):在android.os.Looper.loop(Looper.java:137)
12-11 14:45:38.745:E / AndroidRuntime(26806):在android.app.ActivityThread.main(ActivityThread.java:5103)
12-11 14:45:38.745:E / AndroidRuntime(26806):在java.lang.reflect.Method.invokeNative(本机方法)
12-11 14:45:38.745:E / AndroidRuntime(26806):在java.lang.reflect.Method.invoke(Method.java:525)
12-11 14:45:38.745:E / AndroidRuntime(26806):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
12-11 14:45:38.745:E / AndroidRuntime(26806):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-11 14:45:38.745:E / AndroidRuntime(26806):在dalvik.system.NativeStart.main(本机方法)
12-11 14:45:38.745:E / AndroidRuntime(26806):抛出java.lang.ClassNotFoundException:产生的原因没有在路径上找到的类com.example.marc.CompassActivity:DexPathList [zip文件/数据/app/com.example.marc-1.apk\"],nativeLibraryDirectories=[/data/app-lib/com.example.marc-1,/供应商/ lib中/系统/ lib目录]
12-11 14:45:38.745:E / AndroidRuntime(26806):在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
12-11 14:45:38.745:E / AndroidRuntime(26806):在java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-11 14:45:38.745:E / AndroidRuntime(26806):在java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-11 14:45:38.745:E / AndroidRuntime(26806):在android.app.Instrumentation.newActivity(Instrumentation.java:1061)
12-11 14:45:38.745:E / AndroidRuntime(26806):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
12-11 14:45:38.745:E / AndroidRuntime(26806):... 11个

我做了,为什么会这样搜索,并才知那是因为我的意图的问题。而且,我需要我的活动添加到我的清单文件。然而,这是我的清单文件:

 <清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
包=com.example.marc
安卓版code =1
机器人:=的versionName1.0><用途-SDK
    安卓的minSdkVersion =7
    机器人:targetSdkVersion =7/><应用
    机器人:allowBackup =真
    机器人:图标=@绘制/ ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme>    <活动机器人:名字=com.example.marc.CompassActivity
        机器人:标签=@字符串/ APP_NAME>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.MAIN/>
            <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>    < /活性GT;
< /用途>

,从我所看到的,我的意图是那里的行<活动机器人:名字=com.example.marc.CompassActivity,除非我的思想落后这是完全错误的?

只是为了补全的缘故,这里是我的java文件:

 包com.example.marc;
进口com.unity3d.player.UnityPlayerActivity;进口android.content.Context;
进口android.hardware.Sensor;
进口android.hardware.SensorEvent;
进口android.hardware.SensorEventListener;
进口android.hardware.SensorManager;
进口android.os.Bundle;
进口android.util.Config;
进口android.util.Log;
进口android.app.Activity;公共类CompassActivity扩展UnityPlayerActivity
{
    私有静态最后弦乐TAG =北斗;    私人的SensorManager mSensorManager;
    私人传感器mSensor;    静态的公众持股量xmag;
    静态的公众持股量ymag;
    静态的公众持股量zmag;    私人最终SensorEventListener mListener =新SensorEventListener()
    {
        公共无效onSensorChanged(SensorEvent事件)
        {
        如果(Config.DEBUG)Log.d(TAG,
        sensorChanged(+ event.values​​ [0] +,+ event.values​​ [1] +,+ event.values​​ [2] +));            xmag = event.values​​ [0];
            ymag = event.values​​ [1];
            zmag = event.values​​ [2];
        }        公共无效onAccuracyChanged(传感器传感器,精度INT)
        {
        }
    };    @覆盖
    保护无效的onCreate(捆绑冰柱)
    {
        super.onCreate(冰柱);
        mSensorManager =(的SensorManager)getSystemService(Context.SENSOR_SERVICE);
        mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    }    @覆盖
    保护无效onResume()
    {
        如果(Config.DEBUG)Log.d(TAGonResume);
        super.onResume();        mSensorManager.registerListener(mListener,mSensor,
        SensorManager.SENSOR_DELAY_GAME);
    }    @覆盖
    保护无效的onStop()
    {
        如果(Config.DEBUG)Log.d(TAG的onStop);
        mSensorManager.unregisterListener(mListener);
        super.onStop();
    }    公共静态浮动的getX()
    {
        返回xmag;
    }    公共静态浮动的getY()
    {
        返回ymag;
    }    公共静态浮动盖茨()
    {
        返回zmag;
    }
}

再次按我的想法,这就是我要传递给我的清单文件,例如,它被称为CompassActivity。显然,虽然我一定做错了什么事不然我也不会得到我的错误。可能有人请告诉我这是我在做什么错误/丢失?

修改

最新LogCat中的文件:

  16 12-11:32:16.957:​​E / AndroidRuntime(29055):致命异常:主要
12-11 16:32:16.957:​​E / AndroidRuntime(29055):了java.lang.RuntimeException:无法实例活动ComponentInfo {com.example.marc / com.example.marc.CompassActivity}:抛出java.lang.ClassNotFoundException:没T路径上找到的类com.example.marc.CompassActivity:DexPathList [zip文件/data/app/com.example.marc-2.apk\"],nativeLibraryDirectories=[/data/app-lib/com .example.marc-2 /供应商/ lib中/系统/ lib目录]
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在android.app.ActivityThread.access $ 600(ActivityThread.java:141)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1256)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在android.os.Handler.dispatchMessage(Handler.java:99)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在android.os.Looper.loop(Looper.java:137)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在android.app.ActivityThread.main(ActivityThread.java:5103)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在java.lang.reflect.Method.invokeNative(本机方法)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在java.lang.reflect.Method.invoke(Method.java:525)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在dalvik.system.NativeStart.main(本机方法)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):抛出java.lang.ClassNotFoundException:产生的原因没有在路径上找到的类com.example.marc.CompassActivity:DexPathList [zip文件/数据/app/com.example.marc-2.apk\"],nativeLibraryDirectories=[/data/app-lib/com.example.marc-2,/供应商/ lib中/系统/ lib目录]
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在android.app.Instrumentation.newActivity(Instrumentation.java:1061)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
12-11 16:32:16.957:​​E / AndroidRuntime(29055):... 11个


解决方案

我觉得

 <活动机器人:名字=com.example.marc.CompassActivity

 <活动机器人:名字=CompassActivity

(你已经在包属性提到的com.example.marc
机器人的值:名称应该是名存实亡活动类的。
由于您的清单文件说,主要活动类是com.example.marc.CompassActivity,运行环境寻找,但没有找到它作为你的主要活动类文件被命名为CompassAcitvity)

主要问题是,在运行时无法实例在MainActivity,因为它无法找到DexPathList类com.example.marc.CompassActivity

请参阅方法<一href=\"https://android.googlesource.com/platform/libcore-snapshot/+/ics-mr1/dalvik/src/main/java/dalvik/system/DexPathList.java\"相对=nofollow>的findClass()行310-323

如果成功找到了类,那么类对象返回其他明智的无效它返回到<一个href=\"https://android.googlesource.com/platform/libcore-snapshot/+/ics-mr1/dalvik/src/main/java/dalvik/system/BaseDexClassLoader.java\"相对=nofollow> BaseDexClassLoader(见第58行)与ClassNotFoundException的是空的情况下接收到这是在这种情况下发生的异常。

我觉得无论在构建过程中的主要活动课被排除或具有不同于清单提到的一些不同的名称。

I'm trying to build my Android plugin for Unity. But when I do, I get the follow error log in Logcat:

12-11 14:45:38.745: E/AndroidRuntime(26806): FATAL EXCEPTION: main
12-11 14:45:38.745: E/AndroidRuntime(26806): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.marc/com.example.marc.CompassActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.marc.CompassActivity" on path: DexPathList[[zip file "/data/app/com.example.marc-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.marc-1, /vendor/lib, /system/lib]]
12-11 14:45:38.745: E/AndroidRuntime(26806):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at android.os.Looper.loop(Looper.java:137)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at android.app.ActivityThread.main(ActivityThread.java:5103)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at java.lang.reflect.Method.invokeNative(Native Method)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at java.lang.reflect.Method.invoke(Method.java:525)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at dalvik.system.NativeStart.main(Native Method)
12-11 14:45:38.745: E/AndroidRuntime(26806): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.marc.CompassActivity" on path: DexPathList[[zip file "/data/app/com.example.marc-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.marc-1, /vendor/lib, /system/lib]]
12-11 14:45:38.745: E/AndroidRuntime(26806):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
12-11 14:45:38.745: E/AndroidRuntime(26806):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
12-11 14:45:38.745: E/AndroidRuntime(26806):    ... 11 more

I did a search on to why this is happening and I discovered it is because of a problem with my intent. And that I needed to add my activity to my Manifest file. However, this is my manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.marc"
android:versionCode="1"
android:versionName="1.0" >

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity android:name="com.example.marc.CompassActivity"
        android:label="@string/app_name">
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>
</application>

And from what I can see, my intent is there in the line <activity android:name="com.example.marc.CompassActivity" unless my thinking behind this is entirely wrong?

Just for completions sake, here is my java file:

  package com.example.marc;
import com.unity3d.player.UnityPlayerActivity;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.util.Config;
import android.util.Log;
import android.app.Activity;

public class CompassActivity extends UnityPlayerActivity 
{
    private static final String TAG = "Compass";

    private SensorManager mSensorManager;
    private Sensor mSensor;

    static public float xmag;
    static public float ymag;
    static public float zmag;

    private final SensorEventListener mListener = new SensorEventListener() 
    {
        public void onSensorChanged(SensorEvent event)
        {
        if (Config.DEBUG) Log.d(TAG,
        "sensorChanged (" + event.values[0] + ", " + event.values[1] + ", " + event.values[2] + ")");

            xmag = event.values[0];
            ymag = event.values[1];
            zmag = event.values[2];
        }

        public void onAccuracyChanged(Sensor sensor, int accuracy) 
        {
        }
    };

    @Override
    protected void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
        mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    }

    @Override
    protected void onResume()
    {
        if (Config.DEBUG) Log.d(TAG, "onResume");
        super.onResume();

        mSensorManager.registerListener(mListener, mSensor,
        SensorManager.SENSOR_DELAY_GAME);
    }

    @Override
    protected void onStop()
    {
        if (Config.DEBUG) Log.d(TAG, "onStop");
        mSensorManager.unregisterListener(mListener);
        super.onStop();
    }

    public static float getX()
    {
        return xmag;
    }

    public static float getY() 
    {
        return ymag;
    }

    public static float getZ()
    {
        return zmag;
    }
}

Again, as per my thinking, this is what I should be passing to my Manifest file, such, it is called "CompassActivity". Clearly though I must have done something wrong otherwise I wouldn't be getting the errors I am. Could someone please tell me what it is I am doing wrong / missing?

edit

Latest LogCat files:

   12-11 16:32:16.957: E/AndroidRuntime(29055): FATAL EXCEPTION: main
12-11 16:32:16.957: E/AndroidRuntime(29055): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.marc/com.example.marc.CompassActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.marc.CompassActivity" on path: DexPathList[[zip file "/data/app/com.example.marc-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.marc-2, /vendor/lib, /system/lib]]
12-11 16:32:16.957: E/AndroidRuntime(29055):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at android.os.Looper.loop(Looper.java:137)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at android.app.ActivityThread.main(ActivityThread.java:5103)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at java.lang.reflect.Method.invokeNative(Native Method)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at java.lang.reflect.Method.invoke(Method.java:525)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at dalvik.system.NativeStart.main(Native Method)
12-11 16:32:16.957: E/AndroidRuntime(29055): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.marc.CompassActivity" on path: DexPathList[[zip file "/data/app/com.example.marc-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.marc-2, /vendor/lib, /system/lib]]
12-11 16:32:16.957: E/AndroidRuntime(29055):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
12-11 16:32:16.957: E/AndroidRuntime(29055):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
12-11 16:32:16.957: E/AndroidRuntime(29055):    ... 11 more

解决方案

I think

 <activity android:name="com.example.marc.CompassActivity"

SHOULD BE

   <activity android:name="CompassActivity"

(you already mentioned "com.example.marc" in package attribute The value of android:name should be name of activity class only. Since your manifest file says main activity class is "com.example.marc.CompassActivity", runtime environment looks for it , but it doesn't find it as your main activity class file is named as "CompassAcitvity")

[EDIT]

Main issue is that the runtime is unable to Instantiate the MainActivity because it is not able to find the class "com.example.marc.CompassActivity" in DexPathList

See method "findClass()" line 310-323

If a class is successfully found then a class object is returned other wise null it is returned to BaseDexClassLoader(see line 58) And ClassNotFoundException is thrown in case null is received which is happening in this case.

I think either main activity class is excluded during build process or it has some different name unlike mentioned in manifest.

这篇关于Android的错误了java.lang.RuntimeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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