7

Using Vim Syntastic with an android project. (e.g. com.myproject.project) It's not aware of classes declared within my project but outside of the current file. e.g. the following flags errors:

import com.myproject.project.SomeClass;
...
SomeClass someclass = new SomeClass();
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
lorean
  • 2,150
  • 19
  • 25
  • Syntastic only acts as a middleman between Vim and many external programs. You should 1. find out what program is used to check your code, 2. look in its doc for a way to make it smarter, 3. see if you can configure Syntastic. – romainl May 23 '13 at 19:45
  • Most likely javac is getting confused because you are running it from the wrong directory. – FDinoff May 23 '13 at 20:47
  • Thank you. I'm using it in combination with You Complete Me (YCM). – lorean May 24 '13 at 03:35
  • Make sure you are running it from the correct context (ie make sure to `cd` in vim to the correct project root). Also, you can specify a classpath for syntastic to use by creating a .syntastic_javac_config file in the project root. Adding ./classes or wherever your classes are should fix this. – Troy Patrick Aug 22 '13 at 02:10

2 Answers2

10

Saw this post Configure syntastic to work fine with Android projects which solve the problem:

Method 1:
Inside vim editor

:SyntasticJavacEditClasspath

Then add the following to the buffer window

/path-to-your-app/bin/classes  
/path-to-your-android-sdk/platforms/android-19/*.jar

Method 2:
Add the following to the .vimrc:

let g:syntastic_java_javac_classpath = "/<path-to-your-app>/bin/classes:/<path-to-your-android-sdk>/platforms/android-19/*.jar"
ken
  • 13,869
  • 6
  • 42
  • 36
  • 2
    About method 2! I don't know if any one is having the same situation as mine but I had tried to use ":" to separate multiple classpath but it doesn't work so I tried "\n" and it works. Example: "//bin/classes\n//platforms/android-19/*.jar". Remember that just replace ":" by "\n", mustn't add anything else – minh truong Apr 09 '15 at 04:22
1

Here is a summary of the various methods which worked for me in linux vim7.4 and Syntastic3.7.0-224 with credit to each.

Method 1 - manual creation of .syntastic_javac_config

1. Edit .vimrc and use this syntax:
let g:syntastic_java_javac_config_file_enabled = 1

2. Where you edit your vim files, add this to a file named .syntastic_javac_config

let g:syntastic_java_javac_classpath = '/home/davis/progs/princeton-algos/week1/libs/algs4.jar'

Method 2 - advantage no matter where you edit the class path is known.

1. Edit .vimrc and use this syntax:
let g:syntastic_java_javac_classpath = "/home/davis/progs/princeton-algos/week1/libs/algs4.jar"

This adds the jar and

Method 3 - Automatic generation of .syntastic_javac_config file

1. Edit .vimrc and use this syntax:
let g:syntastic_java_javac_config_file_enabled = 1
2. Edit a java file with vim
3. :SyntasticJavacEditClasspath
When the edit window opens, add the class path without quotes and a newline after each entry the class path. In my case, this is the entry
for the setting includes the current folder as well:
/home/davis/progs/princeton-algos/week1/libs/algs4.jar
.
4 :wq the edit setting window
5. Now the class path is set for syntastic when editing files from that location. If you edit from a new directory, you will need to repeat the process.

Besides the comments above, this post also helped.

netskink
  • 4,033
  • 2
  • 34
  • 46