使用 Eclipse 调试 android 应用程序时“找不到源”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9062036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Source not found" when debugging android app using Eclipse
提问by Searene
Code is as follows, and i set a breakpoint on certain line(i have marked it in the code below, in fact, Eclipse always tells me "source no found", wherever i set the breakpoint):
代码如下,我在某行设置了一个断点(我在下面的代码中标记了它,事实上,Eclipse总是告诉我“找不到源代码”,无论我在哪里设置断点):
package com.app.MainActivity;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Chapter03_ResourceActivity extends Activity {
/** Called when the activity is first created. */
private Button myButton;
final private TextView myTextView = (TextView)findViewById(R.id.text_xml);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myButton = (Button)findViewById(R.id.btn_xml);
myButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
StringBuilder sb = new StringBuilder(); <==Here breakpoint
XmlResourceParser xrp = getResources().getXml(R.xml.test);
int counter = 0;
try {
while(xrp.getEventType() != XmlPullParser.END_DOCUMENT) {
if(xrp.getEventType() == XmlPullParser.START_TAG) {
String name = xrp.getName();
if(name.equals("customer")) {
counter ++;
sb.append(counter + " Customer" + "\n");
sb.append(xrp.getAttributeValue(0) + "\n");
sb.append(xrp.getAttributeValue(1) + "\n");
sb.append(xrp.getAttributeValue(2) + "\n\n");
}
xrp.next();
}
}
myTextView.setText(sb.toString());
} catch(IOException e) {
e.printStackTrace();
} catch(XmlPullParserException e) {
e.printStackTrace();
}
}
});
}
}
Run--Debug, and then i got a prompt: Source not found. why? cannot Eclipse stop on the breakpoint in the code i supply? why does eclipse need more source code?
运行--调试,然后我得到一个提示:找不到源。为什么?Eclipse 不能在我提供的代码中的断点处停止吗?为什么eclipse需要更多的源代码?
回答by Kuffs
Does this help?
这有帮助吗?
Start debugging, and run until you hit a breakpoint
Right click in the Debug view of the Debug perspective (for example on the call stack), and choose "Edit Source Lookup Path"
Add all your projects above "Default", via "Add..." > "Java project" > "Select All"
开始调试,运行直到遇到断点
右键单击 Debug 透视图的 Debug 视图(例如在调用堆栈上),然后选择“Edit Source Lookup Path”
通过“添加...”>“Java项目”>“全选”将所有项目添加到“默认”之上
回答by infrared411
You need to add the android source to your project. The problem is that when you step into an android class file (such as import android.app.Activity), you are stepping away from your code and into an android class file.
您需要将 android 源添加到您的项目中。问题在于,当您进入一个 android 类文件(例如导入 android.app.Activity)时,您正在离开您的代码并进入一个 android 类文件。