I have created a new Java class and wanted to import it in MainActivity. I tried:
import HttpRequest.HttpRequest
And I got:
cannot resolve symbol HttpRequest
What am I doing wrong?
Project structure:
HttpRequest.HttpRequest doesn't exist.
You are importing the wrong class.
It should be:
import com.example.megido.myapplication.HttpRequest;
Also check this link for more info about Android Studio Tips and Tricks.
For quick fixes to coding errors, the IntelliJ powered IDE implements the Alt + Enter key binding to fix errors (missing imports, variable assignments, missing references, etc).
If you want import another Class in Present class then you have to give its full path ie. import com.example.megido.myapplication.HttpRequest
If you trying to import HttpRequest for network request then you have to add the corresponding library to you project.
I hope it helps..
Related
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
Trying to import import GUI.layouts.RXCardLayout; but it can't be resolved. It is an extension of CardLayout that someone made and I found it online. Anyone know what the right import is?
I assume you are talking about this RXCardLayout.
There are no special imports. It doesn't use a package. You just add the source to you project and compile the source code into your class path.
Maybe the problem is you need to add a package statement to put the code into the same package as your other source code.
I imported the samples of Sphero-Android SDK to my workspace. TwoPhonesOneBall project gives compiler errors. In ConnectionActivity.java class, the following imports cannot be resolved.
//...some imports
import orbotix.multiplayer.LocalMultiplayerClient;
import orbotix.multiplayer.MultiplayerControlStrategy;
import orbotix.multiplayer.MultiplayerGame;
import orbotix.multiplayer.RemotePlayer;
//...imports
How can I fix it? Since these classes don't exist, I didn't come up with a solution. I searched the net but I couldn't find similar problem. By the way,the same problem also occurs in MultiplayerLobby application.
I am trying to import the following class for an android project
import android.support.v7.internal.widget.AdapterViewICS.OnItemClickListener;
But I get an error "The type android.support.v7.internal.widget.AdapterViewICS is not visible" All my other imports are working fine thus far and I am using the android ADT bundle downloaded directly from google.
I've got a similar problem after a git merge and, probably, Eclipse being crazy about packages auto-import.
Just replace
import android.support.v7.internal.widget.AdapterViewICS.OnItemClickListener;
with
import android.widget.AdapterView.OnItemClickListener;
The original AdapterView is supported since API Level 1 thus you will not break the app on old devices.
replace the import statement"import android.support.v7.internal.widget.AdapterViewICS.OnItemClickListener;" with "import android.widget.AdapterView.OnItemClickListener;",sometimes Eclipse cannot find the right packages for auto import.
I have the following setup in my project:
com.foo
- Main
com.foo.util
- StringUtil
In Main I import the StringUtil using
package com.foo;
import com.foo.util.StringUtil;
And use it just as you would use it;
StringUtil string = new StringUtil();
Yet, eclipse keeps telling me that StringUtil cannot be resolved to a type - how can this be?
I already tried refreshing the project, reimporting it as a new project, clicked through the build paths but everything seems to be set up correctly.
But still, eclipse doesn't recognize the class and won't compile my project.
EDIT: The original question had this format:
package com.foo;
import com.foo.StringUtil;
Thus my answer was:
Because StringUtil is in com.foo.util and not in com.foo.
Change it to import com.foo.util.StringUtil.
Use CTRL + SHIFT + O shortcut to organize imports automatically. It will save your time.
Can be a typo, but in your import it says import com.foo.StringUtil;, but shoud be import com.foo.util.StringUtil; try press Ctrl-1 (Quick fix) when class is in focus. This gives suggestions on errors
Turns out it was due to some messed up eclipse installation.
Wiping the project, checkout it again and reimport it in a restarted eclipse solved every issue.
Is your class public (Which I believe it is if you can import it) with default constructor there if there are overriden constructor and otherwise no overridden constructor + constructor being public?
Copying the project to a new project solves this issue.