279

I'm trying to use the barbecue barcode printing library. I have successfully added the library to IntelliJ through project structure add library. Then I imported the packages and wrote the methods, which gave me no error. The packages were available in the class.

But when I compile it gives me the error:

error: package net.sourceforge.barbecue does not exist 

How can this be?

I'm coding in ubuntu, is there any other place to which I have to add the library?

3
  • 2
    And you're certain that this JAR is in the Libraries section of your Project Structure? Commented Nov 22, 2013 at 4:30
  • 1
    Verify that the scope of the library (in the project structure window) is Compile. If set to a scope of Provided it will cause the behavior you describe. Commented Nov 22, 2013 at 15:47
  • If you have a dependency under a maven profile, make sure you select the correct profile in the maven tree "Profiles", when you compile the project. Commented Apr 15, 2021 at 16:19

42 Answers 42

1
2
1

I don't know if this may help but I've tried all of the solutions mentioned here and more. NOTHING SEEMS TO WORK.

I even look every related issues raised on github issues in Jetbrains and Nothing.

And I was about to loose my mind and started pulling out my hairs and something cames out to my mind.

What I did was use a <dependencyManagement> </dependencyManagement> on my project and specify all the versions and everything then mvn clean install and then on another project I added the dependency as we normally do then IntelliJ, Vscode, started to recogize my imports and classes.

I hope it will also work for you.

Sign up to request clarification or add additional context in comments.

Comments

0

If you do not want to destroy .idea, you can try :

  • open Project Structure > Modules
  • unmark the java folder as a source folder
  • apply / rebuild
  • then mark it again as a source folder
  • rebuild

Comments

0

In case you're facing very weird "unable to resolve java, sun packages problem", try the following:

  1. Open Project Structure and change Project SDK to another version, example: java 8 -> 9; 11->13, etc, and wait until it re-index all jdk's jars. Switch between jdks with same version may not work! (Ex: jetbrains jdk11 -> openjdk 11)
  2. Open a new project (or create a empty one); pause new project's indexing; close the old one; start indexing; open the old project and pause the new project's indexing and wait.

Comments

0

I tried compile a java 8 project with JDK 12 and has the same issue. None of previous answer solved my problem.

I changed o Shortel Command Line to "JAR Manifest" and worked like a charm.

intellij

Comments

0

I created two new classes under a new package and used it in rest of the code, Intellij was able to resolve these no red highlights were shown in the intellij editor. While building it was showing package doesn't exist error. I tried everything from gradle clean build, rebuild project, clear .idea and .gradle and reimporting the project, clearing the gradle local cache but nothing was working. Finally I refactored the name of the new package and this time intellij was able to recognize the new classes and it started working.

1 Comment

This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review
0

Invalidate caches worked for me but it's too long to recover the caches so I don't have the patience to wait for it. I found another way to solve it in my case. "Repair IDE" step 3 (delete Package search project caches) worked for me perfectly

enter image description here

Comments

0

Follow the steps below:

  1. Ctrl+Shift -> Type Invalidate Caches -> Chech all options except: Ask before...
  2. Superior menu -> Build -> Rebuild Project

Comments

0
package com.example; import com.sun.jna.Library; import com.sun.jna.Native; public class C { public interface Kernel32 extends Library { public void OutputDebugStringA(String Text); public void DebugBreak(); public void Sleep(int a); } public static int incint(int in1) { testpkg.xxxBird.Say("xxxee"); //only use this statement to call external lib //I don't use "import" statement. return in1*2; } } 

I am using intellij idea. You need to add testpkg path in project dependency. enter image description here

Comments

0

I faced the same situation in ver 2022.1.4. I tried all solutions from the first answer, nothing worked except the delete the ".idea" folder. Even through many friends mentioned this solution, I couldn't find this folder, I was looking around user profile and AppData folders. This folder was in fact created under the project folder itself.

I closed the project, and re-opened after deleting this folder.. everything back to normal. It felt like the "Intel" was lost and the IDE was only "lij" for sometime.. lol

Comments

0

For me, to simply quit IntelliJ and reopen it was enough to get beyond this error.

Comments

0

This question's theme seems to be specifically the "missingness" of a given package... so, to anyone that may need an answer to THIS... but not in the context of an external library being imported...

Java's convention specifies that a group(package) can NEVER be composed of a SINGLE subgroup... this means:

/my_package | |-sub_group_a | |-HangingClass.java 

This means that if sub_group_a is created... HangingClass.java will ALSO need its own category. IF this is not done... dependencies of HangingClass.java that are within sub_group_a will NOT BE SEEN... EVEN IF the syntax is structured as a dereference.... since when a dereference structure is used('.' operand)...Intellij WILL NOT mark it as visibility mistake.

example:

HangingClass { public void aFunction(String s) { String res = AClassWithinSubGroupA.ASubClass.someStaticMethod(s); return res; } } 

Now... this may happen accidentally when refactoring your project... and if you commit and publish... the error will not be seen, and the error may appear when trying to use the code on the other importer end

The solution is for BOTH classes to be AT LEAST AT THE SAME DEPTH in the directory tree.

/my_package | |-sub_group_a | | | AClassWithinSubgroupA.java | |-sub_group_b | HangingClass.java 

Now Java will correctly compile.

If you think about it very carefully it makes sense (from a philosophical perspective) that ANY subgroup defined within a containing group... SHOULD define an alternate version of it.

Think about the reddit meme "X implies the existence of Y":

“Dr. Pepper implies the existence of a shadowy, enigmatic figure called simply ‘Dr. Salt.’”

So, for any categorization, the entire group is forked into 2 categories:

  • The category you created
  • The things you don't consider within the created category: "A shadowy, enigmatic package".

Comments

0

I had the same issue; I'd fix it by executing this:

mvn compile 

Comments

1
2

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.