1

Anyone knows how to debug in Android studio?

My program couldn't run due to an exception,

app:compilejavac. 

And it says use debug or stacktrace for more info. Please help me out. All other apps running fine only current project has this errors.

The error message is that :
The error is that: /Users/hexinhao/AndroidStudioProjects/zhbj77/app/build/generated/source/r/debug/com/jikexueyuan/zhbj75/R.java:2431: 错误: 需要';'
        public static final int news_center-body_text=0x7f0c0089;
                                           ^
/Users/hexinhao/AndroidStudioProjects/zhbj77/app/build/generated/source/r/debug/com/jikexueyuan/zhbj75/R.java:2431: 错误: 需要<标识符>
        public static final int news_center-body_text=0x7f0c0089;
                                                     ^
2 个错误

:app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Bruce He
  • 27
  • 7
  • There is menu Run Debug in Android Studio. And for stack trace, at the bottom of Android Studio. – ישו אוהב אותך Jun 29 '16 at 16:22
  • Formatted the code. Please add the errors that you are getting. – Pritam Banerjee Jun 29 '16 at 20:59
  • I am using android studio on Mac, enabling stactrace needs to go to android studio preference, select compiler then adds --stacktrace --debug to the command-line options.Then stacktrace info will print out everytime when we debug our program. – Bruce He Jun 30 '16 at 03:10

1 Answers1

2

news_center-body_text

This has an error at - (the arrow is pointing to it).

Your resource names must reflect valid Java variable rules, so no - characters. Change it to an _ in the ID for that XML element where you have that particular element.


On a related note - How would you expect findViewById(R.id.news_center-body_text) to work?

That would be your first hint that something is wrong.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Thanks a lot. I also found the error after I used stacktrace. Yes, the problem is that I named layout elements in an illegal way,news_center-body_text have to be news_center_body_text. – Bruce He Jun 30 '16 at 03:06