import Task in android eclipse - java

I'm currently learning Android and Java and I am having some issues with importing.
Actually I have downloaded tutorial videos for Android. In them the person declare this:
Task t = new Task(taskname);
in java.class file ...
So eclipse gives him the error and then a red line occurs below Task and then when he hover on the task this line comes up :
import Task (with his package name)
but in my eclipse when I hover on this line this library or import line is not coming up .Where is the problem? I think there is may be some file that I haven't downloaded.

I think no Task class in SDK...see in the example it might be the task name he gave.U try manually writing it! And check whether the error goes!

You need to add a new package under src say for example com.glen.tasks_manager.tasks and add a java class inside named Task.java, so that when you hover to the task code it will provide an import for the package name you just have created including the new java class name.

Related

IDEA JAVAFX Project can't use library which has been imported with maven

enter image description here
Just like what the picture shows, I've already add dependency in "pom.xml".
And just like expected, "External Library" shows the jar I've imported.
But the truth is that, I can't use them!
The code as shown on your screenshot does not compile either way, you need to
use the class with valid Syntax such as Player p;
import it using import javazoom.jl.player.Player;

Intellij class Import being added to object not the top of class

I've just started a new IntelliJ project. When I try and import a java class with the IntelliJ import shortcut, the import is being added to the object and not to the top of the class like it normally would.
Where in the settings can I change this?
See Preferences/Settings > Editor > Code Style > Java if this option ...
Use fully qualified class names
... is ticked then IntelliJ will always use fully qualified class names. If you disable this option then Intellij will include the import statement and refer to the class by its 'simple' name.
Here's a screenshot showing this configuration item:
If the accepted answer is not working for anyone, Try the below points too.
Check whether the class file is in correct package and resolve if there is any issues in the class file.
Click File -> Invalidate Caches/ Restart and Click Invalidate and Restart button, Once it restarted U'll be able to import properly.
I was facing this issue with my custom / generated(protobuf) java packages.
Solution (TDLR)
Whenever you face this issue, just check the package or class that getting imported doesn't have any error(red marking).
If so try to fix that.
I was having an issue with package naming and its actual location. By generated-sources -> Right Click -> Mark Directory As -> Sources Root corrected my issue.
Check whether generated-sources or folder under the generated sources need to mark us Sources Root.
My issue was with generated java files (Adding this just to help someone else with same issue)
Intellij shows red mark for Import with wildchar(import pkg1.subpkg1.*;). Like editor was unable to recognizing 'import all' under a package.
But direct import to the inner package was fine.
On top of that an resolving issue with import class add full package to the Class itself, instead of adding import statement on top the java file.
This issue didn't affect the code compilation, only in editor it was showing red mark.

I can't import TAudioFileFormat

I use netbeans 6.9.1.
All I want to do is to get the total length of an mp3 song. What I know is this requires tritonus.jar and I have downloaded that and I have imported it to my src file of the package. And it appears in my projects tab under the package in which the JFrame I want to import it(TAudioFileFormat) lives.
To import it, I type
import org.tritonus.share.sampled.file.TAudioFileFormat;
Is there any error in what I have typed? Because everytime the error shows that
package org.tritonus.share.sampled.file does not exist
and I can very well see it there...
Also, when I type the import, when I put a full stop after org, it doesn't show tritonus in that drop down thing.
I apologise for not knowing the proper terms of things.

How to import correct package for StdDraw?

I want to use the StdDraw package, and I've tried many different ways of importing it.
Of course I tried:
import StdDraw;
But, when I look at the documentation from Princeton here, it shows that StdDraw is part of Objects, so I try this:
import java.lang.Object.StdDraw;
However, this results in an error:
error: cannot find symbol in
import java.lang.Object.StdDraw;
I saw this question here but it does not answer this question either.
How do I import StdDraw? thank you.
if you want to use StdDraw you must have
either the sources
or the classes (best zipped up as jar)
as preferred way you use the sources (see http://introcs.cs.princeton.edu/java/15inout/). it says there "To use these libraries, download StdIn.java, StdOut.java, StdDraw.java, and StdAudio.java into the same directory as your program. "
once you did this the imports should be working.
NOTE: all four files are not in packages, so you should 'download' them into the 'standard' package. That means you have to download them to the root package of your project.
by the way: don't import import java.lang.Object.StdDraw; but do just import import StdDraw;
First of all check encoding of your IDE. It should be set to UTF-8. It is important if you are using MS Windows operating system.
Then create StdDraw.java class in the same package as the package of your program you are writing. Remove class declaration, leave only package declaration.
Then visit this page: https://introcs.cs.princeton.edu/java/stdlib/StdDraw.java .
Copy all its contents (Ctr-A, Ctrl-C) and then paste it into StdDraw.java file you created previously.
StdDraw.java has its own main method so try to run it in order to check that the library works correctly. You should see a window with four strange figures :) .
Don't touch StdDraw.java anymore. Now you can easily import StdDraw library and refer to its methods with name of the class.
Enjoy

Eclipse type / import error with built java file

I have a project where we use a ant buildfile to create some .java files. Those built files need to reference to already existing other java files.
My problem is that the built file can have a code line as for example
arg = (Expr) new Ast.BinaryOP(lhs, BOp.B_MINUS, rhs);
where it will show an error "Ast.BinaryOP cannot be resolved to a type". I then can type Ast.BinaryOP again and use autocomplete to pick the BinaryOP part and the error will disappear. The same with BOp.B_MINUS.
I did import (probably way too many times) the necessary other files as far as I can tell.
I.e.
import cd.ir.Ast;
import cd.ir.Ast.*;
import cd.ir.Ast.Expr;
import cd.ir.Ast.BinaryOp;
import cd.ir.Ast.BinaryOp.BOp;
So far I tried
restarting Eclipse
'clean' the project
to just run the project anyway (doesn't work)
remove the "Ast." part which will work once again if I do it in Eclipse but not if generated that way
Google the problem, respectively search it on Stackoverflow which turned out to be hard as there are many related issues. There are no good keywords as far as I can tell.
deleted the project from Eclipse and imported it newly
I need to repeatedly run the ant build file to test the code from where the .java file is generated, thus changing all errors manually is not an option.
Thanks for any advice/help in advance. I will gladly provide more information if you tell me what could help.
Hit F5 on the project, open the file, and then try hitting Ctrl+Shift+O to automatically organize the imports.
After consulting with a friend who didn't see the issue either I finally found it. So logical in retrospect but small enough that I spend 2,5h trying to find it:
import cd.ir.Ast.BinaryOp;
vs:
new Ast.BinaryOP(....
BinaryOp vs. BinaryOP

Categories