Android App,“源未找到”调试错误 - 尝试下载Android源代码

时间:2010-08-30 00:45:07

标签: java android

我的Android应用中出现“找不到源”并导致程序崩溃的错误。我已经阅读了很多帖子说解决方案是下载android源代码并在Eclipse中加载,但我试着无济于事。

以下是一些可能对我的问题有所帮助的信息,如果您需要更多信息,请告诉我们!

堆栈:

Thread [<1> main] (Suspended (exception RuntimeException))
ActivityThread.performLaunchActivity(ActivityThrea d$ActivityRecord, Intent) line: 2663
ActivityThread.handleLaunchActivity(ActivityThread $ActivityRecord, Intent) line: 2679
ActivityThread.access$2300(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 125
ActivityThread$H.handleMessage(Message) line: 2033
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4627
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 868
ZygoteInit.main(String[]) line: 626
NativeStart.main(String[]) line: not available [native method]

第一个条目是'ActivityThrea d'并且'd'被截断是不是很奇怪?如果这是问题,出了什么问题,我该如何解决?

调试停止的代码行:

public void AddAnimationID(String index, Integer view)
{
 animations.put(index, view);
}

'animations'是一个词典,是Alien类的成员。我称之为:

Alien alien;
alien.AddAnimationID("idle", R.drawable.idle);

我认为R.drawable.idle是一个int对吗? findViewByID为参数获取一个int ...

这是logcat,我试图查明它在日志中启动应用程序的位置,对不起,如果它太多了。

I/ActivityManager(   59): Displayed activity com.android.launcher/com.android.la
uncher2.Launcher: 21357 ms (total 21357 ms)
I/Launcher.Model(  118): not binding apps: no Launcher activity
D/dalvikvm(  118): GC_EXPLICIT freed 5222 objects / 297520 bytes in 114ms
D/dalvikvm(  118): GC_EXPLICIT freed 11360 objects / 562112 bytes in 94ms
D/PackageParser(   59): Scanning package: /data/app/vmdl45576.tmp
I/PackageParser(   59): Game.Main: compat added android.permission.WRITE_EXTERNA
L_STORAGE android.permission.READ_PHONE_STATE
I/PackageManager(   59): Removing non-system package:Game.Main
I/ActivityManager(   59): Force stopping package Game.Main uid=10032
D/dalvikvm(  118): GC_EXTERNAL_ALLOC freed 319 objects / 18064 bytes in 73ms
D/dalvikvm(   59): GC_FOR_MALLOC freed 6857 objects / 349752 bytes in 400ms
D/PackageManager(   59): Scanning package Game.Main
I/PackageManager(   59): Package Game.Main codePath changed from /data/app/Game.
Main-2.apk to /data/app/Game.Main-1.apk; Retaining data and using new
I/PackageManager(   59): /data/app/Game.Main-1.apk changed; unpacking
D/installd(   34): DexInv: --- BEGIN '/data/app/Game.Main-1.apk' ---
I/ActivityManager(   59): Starting activity: Intent { act=android.intent.action.
MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=Game.Main/.Main }

D/dalvikvm(  258): DexOpt: load 116ms, verify 200ms, opt 2ms
D/installd(   34): DexInv: --- END '/data/app/Game.Main-1.apk' (success) ---
W/PackageManager(   59): Code path for pkg : Game.Main changing from /data/app/G
ame.Main-2.apk to /data/app/Game.Main-1.apk
W/PackageManager(   59): Resource path for pkg : Game.Main changing from /data/a
pp/Game.Main-2.apk to /data/app/Game.Main-1.apk
D/PackageManager(   59):   Activities: Game.Main.Main
I/ActivityManager(   59): Force stopping package Game.Main uid=10032
E/Launcher(  118): Unable to launch. tag=ApplicationInfo(title=Alien Game) inten
t=Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]
 flg=0x10200000 cmp=Game.Main/.Main }
E/Launcher(  118): android.content.ActivityNotFoundException: Unable to find exp
licit activity class {Game.Main/Game.Main.Main}; have you declared this activity
 in your AndroidManifest.xml?
E/Launcher(  118):      at android.app.Instrumentation.checkStartActivityResult(
Instrumentation.java:1404)
E/Launcher(  118):      at android.app.Instrumentation.execStartActivity(Instrum
entation.java:1378)
E/Launcher(  118):      at android.app.Activity.startActivityForResult(Activity.
java:2817)
E/Launcher(  118):      at com.android.launcher2.Launcher.startActivityForResult
(Launcher.java:1053)
E/Launcher(  118):      at android.app.Activity.startActivity(Activity.java:2923
)
E/Launcher(  118):      at com.android.launcher2.Launcher.startActivitySafely(La
uncher.java:1462)
E/Launcher(  118):      at com.android.launcher2.AllApps2D.onItemClick(AllApps2D
.java:178)
E/Launcher(  118):      at android.widget.AdapterView.performItemClick(AdapterVi
ew.java:284)
E/Launcher(  118):      at android.widget.AbsListView$PerformClick.run(AbsListVi
ew.java:1696)
E/Launcher(  118):      at android.os.Handler.handleCallback(Handler.java:587)
E/Launcher(  118):      at android.os.Handler.dispatchMessage(Handler.java:92)
E/Launcher(  118):      at android.os.Looper.loop(Looper.java:123)
E/Launcher(  118):      at android.app.ActivityThread.main(ActivityThread.java:4
627)
E/Launcher(  118):      at java.lang.reflect.Method.invokeNative(Native Method)
E/Launcher(  118):      at java.lang.reflect.Method.invoke(Method.java:521)
E/Launcher(  118):      at com.android.internal.os.ZygoteInit$MethodAndArgsCalle
r.run(ZygoteInit.java:868)
E/Launcher(  118):      at com.android.internal.os.ZygoteInit.main(ZygoteInit.ja
va:626)
E/Launcher(  118):      at dalvik.system.NativeStart.main(Native Method)
I/installd(   34): move /data/dalvik-cache/data@app@Game.Main-1.apk@classes.dex
-> /data/dalvik-cache/data@app@Game.Main-1.apk@classes.dex
D/PackageManager(   59): New package installed in /data/app/Game.Main-1.apk
I/ActivityManager(   59): Force stopping package Game.Main uid=10032
I/ActivityManager(   59): Start proc com.svox.pico for broadcast com.svox.pico/.
VoiceDataInstallerReceiver: pid=259 uid=10028 gids={}
D/dalvikvm(  157): GC_EXPLICIT freed 4079 objects / 247824 bytes in 605ms
D/dalvikvm(   59): GC_EXPLICIT freed 6136 objects / 382312 bytes in 493ms
W/RecognitionManagerService(   59): no available voice recognition services foun
d
I/installd(   34): unlink /data/dalvik-cache/data@app@Game.Main-2.apk@classes.de
x
D/AndroidRuntime(  191): Shutting down VM
D/jdwp    (  191): adbd disconnected
I/AndroidRuntime(  191): NOTE: attach of thread 'Binder Thread #3' failed
I/ActivityThread(  259): Publishing provider com.svox.pico.providers.SettingsPro
vider: com.svox.pico.providers.SettingsProvider
D/AndroidRuntime(  269):
D/AndroidRuntime(  269): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
D/AndroidRuntime(  269): CheckJNI is ON
D/AndroidRuntime(  269): --- registering native functions ---
I/ActivityManager(   59): Starting activity: Intent { act=android.intent.action.
MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=Game.Main/.Main }

I/ActivityManager(   59): Start proc Game.Main for activity Game.Main/.Main: pid
=273 uid=10032 gids={1015}
I/ARMAssembler(   59): generated scanline__00000077:03545404_00000004_00000000 [
 47 ipp] (67 ins) at [0x322b68:0x322c74] in 4370882 ns
W/Game.Main.Main(  273): SIS is null
D/AndroidRuntime(  273): Shutting down VM
W/dalvikvm(  273): threadid=1: thread exiting with uncaught exception (group=0x4
001d800)
E/AndroidRuntime(  273): FATAL EXCEPTION: main
E/AndroidRuntime(  273): java.lang.RuntimeException: Unable to start activity Co
mponentInfo{Game.Main/Game.Main.Main}: java.lang.NullPointerException
E/AndroidRuntime(  273):        at android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2663)
E/AndroidRuntime(  273):        at android.app.ActivityThread.handleLaunchActivi
ty(ActivityThread.java:2679)
E/AndroidRuntime(  273):        at android.app.ActivityThread.access$2300(Activi
tyThread.java:125)
E/AndroidRuntime(  273):        at android.app.ActivityThread$H.handleMessage(Ac
tivityThread.java:2033)
E/AndroidRuntime(  273):        at android.os.Handler.dispatchMessage(Handler.ja
va:99)
E/AndroidRuntime(  273):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  273):        at android.app.ActivityThread.main(ActivityThrea
d.java:4627)
E/AndroidRuntime(  273):        at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime(  273):        at java.lang.reflect.Method.invoke(Method.java:5
21)
E/AndroidRuntime(  273):        at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(  273):        at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:626)
E/AndroidRuntime(  273):        at dalvik.system.NativeStart.main(Native Method)

E/AndroidRuntime(  273): Caused by: java.lang.NullPointerException
E/AndroidRuntime(  273):        at Game.Main.Main.onCreate(Main.java:81)
E/AndroidRuntime(  273):        at android.app.Instrumentation.callActivityOnCre
ate(Instrumentation.java:1047)
E/AndroidRuntime(  273):        at android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2627)
E/AndroidRuntime(  273):        ... 11 more
W/ActivityManager(   59):   Force finishing activity Game.Main/.Main
I/ActivityManager(   59): Starting activity: Intent { act=android.intent.action.
MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=Game.Main/.Main }

D/AndroidRuntime(  269): Shutting down VM
D/jdwp    (  269): adbd disconnected
I/AndroidRuntime(  269): NOTE: attach of thread 'Binder Thread #3' failed
W/ActivityManager(   59): Activity pause timeout for HistoryRecord{43ed84f8 Game
.Main/.Main}
I/ARMAssembler(   59): generated scanline__00000077:03515104_00000000_00000000 [
 33 ipp] (47 ins) at [0x305640:0x3056fc] in 1148283 ns
W/ActivityManager(   59): Launch timeout has expired, giving up wake lock!

以下是Alien班:

package Game.Main;

import java.util.Dictionary;

import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;

public class Alien 
{
    private AlienState state;
    private Dictionary<String, Integer> animations;
    private ImageView imageView;

    public Alien()
    {

    }

    public void AddAnimationID(String index, Integer view)
    {
        animations.put(index, view);
    }

    public Integer GetAnimationID(String index)
    {
        return animations.get(index);
    }

    public void SetImageView(ImageView view)
    {
        imageView = view;
        if(animations.get("idle") != null)
        {
            imageView.setBackgroundResource(R.drawable.idle);
            state = AlienState.idle;
        }
    }

    public ImageView GetImageView()
    {
        return imageView;
    }

    public void ChangeView(String index)
    {
        if(animations.get(index) != null)
        {
            imageView.setBackgroundResource(animations.get(index));
            state = AlienState.valueOf(index);
        }
    }
}

以下是调用它的onCreate函数及相关信息:

package Game.Main;

import java.util.ArrayList;
import java.util.List;

import Game.Main.MainView.MainThread;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class Main extends Activity implements OnClickListener {

    private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;

    private ArrayList<String> dictionary;
    private TextView txtText;

    private MainThread thread;
    private MainView view;

    private AnimationDrawable anim;

    private Alien alien;

    @Override // called when Main is created.
    public void onCreate(Bundle savedInstanceState) {

        // reload from previous instance
        super.onCreate(savedInstanceState);

        // set default content view
        setContentView(R.layout.main);

        view = (MainView)findViewById(R.id.mainView);
        thread = view.GetThread();

        if (savedInstanceState == null) {
            // we were just launched: set up a new game
            thread.SetState(GameState.Active);
            Log.w(this.getClass().getName(), "SIS is null");
        } else {
            // we are being restored: resume a previous game
            thread.RestoreState(savedInstanceState);
            Log.w(this.getClass().getName(), "SIS is nonnull");
        }



        // setup speak button
        Button speakButton = (Button)findViewById(R.id.btn_speak);

        // setup text box
        txtText = (TextView)findViewById(R.id.txt_text);

        // setup our dictionary
        dictionary = new ArrayList<String>();
        dictionary.add("sit");
        dictionary.add("eat");
        dictionary.add("jump");
        dictionary.add("think");

        alien.AddAnimationID("idle", R.drawable.idle);
        alien.AddAnimationID("eat", R.drawable.eat);
        alien.AddAnimationID("jump", R.drawable.jump);
        alien.AddAnimationID("think", R.drawable.think);
        alien.AddAnimationID("run", R.drawable.run);
        alien.AddAnimationID("sit", R.drawable.sit);
        alien.SetImageView((ImageView)findViewById(R.id.alien_image));

        // check to see if a recognition activity is present
        PackageManager pm = getPackageManager();
        List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);

        // if activities were found, cancel speech recognition
        if (activities.size() != 0)
            speakButton.setOnClickListener(this);
        else 
        {
            speakButton.setEnabled(false);
            speakButton.setText("Recognizer not present");
        }
    }

我在Windows 7 x64上使用Eclipse。我拥有Android SDK的所有最新更新,我下载了android源代码,并将其添加到Eclipse补丁中,因为以前的帖子让我尝试了。调用第一次AddAnimationID时,代码会中断调试。我希望这就是你需要的一切,谢谢!对不起,顺便说一下我做错了,我对此有些新意。

编辑:看起来我没有足够的断点,罪魁祸首不是AddAnimationID函数,而是实际上是SetImageView函数。 if语句似乎不起作用,所以我暂时评论它。一旦我弄明白,我会回复。它可能是一种愚蠢的东西,适用于另一种语言而不是Java ......

2 个答案:

答案 0 :(得分:12)

问题最终成为了Dictionary类,我通过投入一堆try / catch块来模糊地工作,但这不是我想要的,所以我用Map替换它并且它工作正常。

要添加一些我从那时以来发现的有用信息到这个答案,因为有相当多的人访问过这个页面:Eclipse会在您的应用程序中发出的几乎每个随机错误都会说“Source not found”。以下是为了找到这些麻烦的代码行而要遵循的一些步骤:

1)逐行浏览代码(使用步骤过滤器忽略您未编写的代码),直到找到有问题的行,这很可能是您犯错误的地方。如果代码中的错误很深,请在您认为问题发生的位置靠近但不是之后放置一个断点,并从那里开始。

2)有时可以在“变量”面板中找到未捕获的异常和其他有用信息。

3)“未找到源”仅表示生成异常的代码行在二进制文件中。它确实存在,Eclipse无法向您显示它。

答案 1 :(得分:0)

我的项目中有同样的问题,引用了一个库项目。问题的原因是图书馆项目中存在的一项活动,我忘记在我的项目manifest.xml文件中提及它。