安卓:无法实例活动/ ClassNotFoundException的 [英] Android: Unable to instantiate activity / ClassNotFoundException
问题描述
我最近出版的一个应用程序市场,我现在得到一个错误的一些用户,应用程序presumably崩溃权当它开始。不幸的是,我不能和他联系,直接和应用程序正常工作在模拟器,以及我的手机(和一些朋友的电话)
编辑:我想,出现这种情况给多个用户,因为我收到的评论像崩溃的开始或不工作的市场。我只收到这一个堆栈跟踪,但有关于配置,设备,Android版本等。
I recently published an app to the market and I'm now getting an error by some user, the app presumably crashes right when it starts. Unfortunately I can't contact him directly and the app works fine in the emulator as well as on my phone (and some friends' phones).
I guess that this happens to more than one user as I received comments in the market like "crashes on start" or "doesn't work". I only received this one stacktrace but there's no info about the configuration, device, Android version, etc.
该应用程序是一个简单的音板,所以真的没有神奇的参与,但我不知道为什么它不能在某些手机上。这里的堆栈跟踪我得到的,我希望有人能帮助我了:
The app is a simple soundboard, so there's really no magic involved, but I can't get why it fails on some phones. Here's the stack trace I'm getting, I hope anybody can help me out:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.my.app/com.my.app.SoundMachine}: java.lang.ClassNotFoundException: com.my.app.SoundMachine in loader dalvik.system.PathClassLoader[/mnt/asec/com.my.app-1/pkg.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.my.app.SoundMachine in loader dalvik.system.PathClassLoader[/mnt/asec/com.my.app-1/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
... 11 more
这些都是第一对夫妇从我的活动线路:
These are the first couple of lines from my activity:
public class SoundMachine extends Activity {
private SoundManager mSoundManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
编辑:这是(几乎)完整的onCreate:
This is the (almost) complete onCreate:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mSoundManager = new SoundManager();
mSoundManager.initSounds(getBaseContext());
int counter = 0;
for (Integer soundFile : soundFiles) {
counter++;
mSoundManager.addSound(counter, soundFile);
}
ImageButton SoundButton1 = (ImageButton) findViewById(R.id.sound1);
SoundButton1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mSoundManager.playSound(1);
}
});
SoundButton1.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
saveSoundChoice(soundFiles[0], soundNames[0]);
return true;
}
});
(...more of this...)
Button StopButton = (Button) findViewById(R.id.stopbutton);
StopButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mSoundManager.stopAll();
}
});
}
和这里是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.app" android:installLocation="preferExternal"
android:versionCode="9" android:versionName="1.2">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".SoundMachine" android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8" />
</manifest>
所以,我已经读到这里,并在一些论坛上所有可能的错误并不适用于我的应用程序。
So all possible errors I already read about here and in some forums don't apply to my app.
- 在该活动是在manifest present。
- 超级方法被调用的覆盖方法。
- 的内容查看在视图中访问元素之前设置。
我知道这很难找出错误的根源,而不能复制,但也许有人有一个好主意,可以帮助我。
I know it's hard to pinpoint the source of an error without being able to reproduce it, but maybe somebody has a bright idea and can help me out.
几个问题:
- <打击>我需要在清单中的意图-part? Eclipse中创建它,当我创建的项目。击>(是的,根据梅拉)
- <打击>如果超方法来调用它在哪里?击>(是的,根据梅拉)
Do I need the "intent"-part in the manifest? Eclipse created it when I created the project.(Yes, according to Mayra)Should the super-method be called where it is?(Yes, according to Mayra)
编辑:为什么在PathClassLoader的路径是从我的包名称不同:现在剩下的就是主要的问题?页面约翰Ĵ史密斯发布似乎处理同样的问题,但我不明白,是应用存在的修补程序。
The main question that remains now is: How come the path in PathClassLoader is different from my package-name? The page John J Smith posted seems to deal with the same problem, but I don't understand the fix that was applied there.
谢谢,Select0r
Thanks, Select0r
推荐答案
由于ADT更新到版本22(2013年5月),你要检查Android的私人图书馆复选框中的项目 - >属性 - > Java构建路径 - >订单和出口的在Eclipse为您的旧项目,以摆脱这种异常的...
Since ADT update to revision 22 (May 2013) you have to check "Android Private Libraries" check box in Project -> Properties -> Java Build Path -> Order and Export in Eclipse for your older projects to get rid of this exception ...
这篇关于安卓:无法实例活动/ ClassNotFoundException的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!