59

When editing XML files in the editor for Eclipse, line numbers are not displayed.

Use case:

I create a layout with many views, one of these lacks android:layout_width attribute. This causes a runtime error when the binary XML layout resource is inflated. The error log tells me to check like 361 in my XML file.

Thanks to the line number being displayed I can find the offending line and make the change without having to open the file in another editor.

Zoe
  • 27,060
  • 21
  • 118
  • 148
MR Mido
  • 1,618
  • 4
  • 25
  • 35
  • Note: Eclipse 4.4 will display the line number **by default**! See [my answer below](http://stackoverflow.com/a/27432112/6309) (Dec. 2013) – VonC Dec 11 '14 at 20:49
  • According to Android Studio, [this](http://stackoverflow.com/a/32667309/2486904) answer may seem useful. – teobais Dec 01 '15 at 15:06

9 Answers9

166

try right clicking the grey bar and selecting show line numbers it works for me so hopefully it will for u too

enter image description here

enter image description here

or change it in the settings

File > Settings > Editor > Appearance then click the "Show line numbers" box.

computingfreak
  • 4,939
  • 1
  • 34
  • 51
owen gerig
  • 6,165
  • 6
  • 52
  • 91
36

If you're using Android Studio, you can show the line numbers by going to File > Settings > Editor > General > Appearance, then check the "Show line numbers" box.

UPDATE: Android Studio v1.5+ enter image description here

1) Click inside the editor, Command + Shift + A, and type "show line numbers"

2) Select the second option in Preferences and it will take you to the screen that used to exist in General > Appearance

3) Check the "Show Line Numbers" box

whyoz
  • 5,168
  • 47
  • 53
  • 1
    I do not see this option in android studio 2.0, For 2.0 it's under *Android Studio* (top left) > Settings >... – Tim Nuwin Jan 15 '16 at 19:59
  • 1
    @TimNuwin strange...I updated my answer to find the "Show line numbers" box in Mac's Android Studio v1.5+ (probably the same for Windows versions). – whyoz Jan 17 '16 at 14:58
10

File > Settings > Editor > Appearance then click the "Show line numbers" box.

enter image description here

Sonia John Kavery
  • 2,099
  • 2
  • 20
  • 36
6

In eclipse: Windows > Preferences > General > Editors > Text Editors check: "show line numbers" It is not checked by default. It is for both source code and xml files (at least in helios)

John S.
  • 1,937
  • 2
  • 18
  • 28
5

To make the line numbers always show for Android Studio:

File > Settings > Editor > Appearance then click the "Show line numbers" box.

The accepted answer works, but it will only make the line numbers visible on the active editor.

Hunter S
  • 1,293
  • 1
  • 15
  • 26
2

On OS X: Android Studio (top left of the screen) > Preferences > Editor > Appearance.

0

Dec 2013: Starting with Eclipse 4.4, you won't have to look for an option to see line numbers, because they will be visible by default.

Regarding Android Studio, this is another story: since May 2013, Android Studio 0.3.x+ is based on IntelliJ IDEA.
See "How can I permanently have line numbers in IntelliJ?".


Lars Vogel just published on his blog:

Line numbers are default in Eclipse SDK Luna (4.4) as of today

(December 10, 2013)

We conducted a user survey if users want to have line numbers activated in text editors in the Eclipse IDE by default.
The response was very clear:

YES : 80.07% (1852 responses)
NO  : 19.93% (461 responses)
Total  : 2313
Skipped:   15

With Bug 421313, Review - Line number should be activated by default, we enabled it for the Eclipse SDK build, I assume other Eclipse packages will follow.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

I know this is an old question but I just came across the problem so I had to find a solution for my self. I assume the menu has changed a bit based on the previous answers that I am reading. So here is how to do it on Android Studio 1.5 on MAC.

You first click on the window "editor" that you want to see the numbers and then simply choose one of the two proposed solutions under.

The easiest way is simply right click on the grey bar as owen-gerig shows, which I think is the easiest, but if you want to set it through the menu you can via View -> Active Editor -> Show Line Numbers. Hope this helps.

Line Numbering on Android Studio 1.5 for MAC

Thanos
  • 1,618
  • 4
  • 28
  • 49
0

To make the line numbers show always in your android studio, follow this, go to: File > Settings > Editor > General > Appearance and then check the "Show line numbers" box especially if you are using AS 2.1.1. Picture here below...How to show line numbers in Android Studio 2.1.1