1

I'm using Intellij to develop a Java project. However, I've been stuck in a annoying dependency problem. I'm trying to import:

import org.json.JSONException;
import org.json.simple.parser.ParseException;

But when I hit run, the compiler gives me the following errors:

Error:(23, 16) java: cannot find symbol
  symbol:   class JSONException
  location: package org.json
Error:(34, 44) java: cannot find symbol
  symbol:   class JSONException
  location: class com.test.util.metrics.ClientTest

At first it seems to be a typical maven dependency problem, but it turns out I still failed to solve it. I've tried:

1/ add json dependency to .xml file:

<java.version>1.8</java.version>
<jsonSimple.version>1.1</jsonSimple.version>
...
<dependency>
    <groupId>com.googlecode.json-simple</groupId>
    <artifactId>json-simple</artifactId>
    <version>${jsonSimple.version}</version>
</dependency>
...
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${mavenCompilerPlugin.version}</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
...

2/ In Intellij, hit Maven and Reimport

3/ In Intellij, hit Maven and Generate Source and Update Folders

4/ In Intellij, hit Maven and Download Sources and Documentation

But none of the above 4 works, still the same error message.

Could anyone give me some suggestions on this? I know it's a daily problem, but I still cannot solve this... Thanks in advance.

bryanyang
  • 25
  • 6
  • Have you tried to invalidate the caches and restart IntelliJ? Sometimes there is nothing wrong with your dependencies (you can verify it by running mvn clean install from command line for example). In such cases there is probably a corrupt cache in IntelliJ causing the issues. To invalidate: File -> Invalidates caches / restart -> click: Invalidate and restart. – BitfulByte Apr 18 '18 at 04:46
  • See http://stackoverflow.com/a/42427510/104891 – CrazyCoder Apr 18 '18 at 05:02
  • @PimHazebroek thanks for this suggestion, but still not working – bryanyang Apr 18 '18 at 05:13
  • @Bruce Young, too bad. Do you have the same result when running maven from command line? – BitfulByte Apr 18 '18 at 05:21

1 Answers1

0

Try below dependency

<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20180130</version>
</dependency>

Hope this will work..

Nidhi257
  • 754
  • 1
  • 5
  • 23