Android Studio not recognizing String - java

I've encountered a weird glitch in Android Studio:
As you can see it thinks that it is an error:
'class' or 'interface' expected
But it runs and build just fine, so is this just a visual glitch or can it have any effect during compiling?
I'm running Android Studio 0.5.8 for Mac
Things I've tried so far:
Restart Android Studio
Restart MacBook
Invalidate caches and restart
tried other strings (like "en-US" this result in the same effect)
If I use a string through the resources the glitch isn't visible (which it will be eventually, I'm just curious why this is happening)

IntelliJ and Android Studio have the ability to take string parameters and treat the strings as being in another language. For example, if you have a method that takes a string that's HTML, if you tell the IDE about it, it can give you syntax highlighting and content assist with the HTML in that string.
I think you've inadvertently set this string as being treated as Java, and it's giving you the Java syntax errors on it. You need to un-set that setting. Select the text, bring up the Search Action feature (on Mac it's ⌘ shift a). In the search box that comes up, search for Un-inject Language/Reference, as shown in the screenshot below:

try this
httpReqquest.addHeader("Accept-Language","en-US");

Since Android Studio is a bit raw, you can face the "glitches" in many different ways. They're annoying but don't affect the result, as you said. However, I personally don't think that we should endure the inconveniences (even if the Studio costs nothing).
I see a couple of solutions:
Continue with AS and ignore these weird things, hoping they will release a robust software once
Or, to migrate to IntelliJ IDEA as I did. The procedure is pricey but it's worth it.

Related

Java failures in Visual Studio Code

I've attached two images to quickly display what I'm talking about.
It seems to effect my environment in incredibly annoying ways, such as no auto-complete for things like variables (every time I want to utilize a variable or parameter I have to literally type is every single time).
I tried restarting VSC, as well as uninstalling and reinstalling plugins. I also did a chkdsk for errors and corrected them but that seemed to have no correlation to the issues I've been having.
Interestingly enough I've also been having some other issues with my computer, such as my mail app not working anymore (it throws an error code), and not being able to connect to other microsoft products. Not sure if it's related but it seems to have began around the same time.
Reinstall the Java extension or update to a pre-release version.
Press CTRL + SHIFT + P, and type Java: Clean Java Language Server Workspace. to clean up the workspace and restart vscode.

Eclipse: Disable auto completion but keep showing suggestions

After a long period of creating apps with Android Studio I returned to Eclipse to program a pure Java application. Of course, I have noticed large differences in terms of auto completion between IntelliJ IDEA and Eclipse but IntelliJ is no alternative for me because of various reasons.
That is why I started to change the settings in Eclipse, inter alia, for the content assist. I want to have suggestions for variable names too, without having to write a dot first. As you can see in this image, I have changed the auto activation triggers to ._#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ as suggested in another thread on Stack Overflow.
The problem is, if I write short variable names like d it completes them automatically to something different (in this case DEFAULT_CURSOR) when I press the dot key. To avoid this, I have to choose the variable first, before pressing the dot key.
However, having to do it this way is a large waste of time. Is there a possibility to use the suggested variables or methods only when I have pressed the enter key, just like in IntelliJ?
Maybe there is an option to bind the dot key to the closing of the content assist?
No, Eclipse and IntelliJ are different and IntelliJ's level of auto completion is unique to itself. If you are comfortable with it, you should use it and then copy and paste to eclipse for windowbuilder. Also FYI there is a free alternative to windowbuilder for IntelliJ, you can read about it here: WindowBuilder equivalent for IntelliJ?

Real-time compilation in IntelliJ IDEA

I have recently switched from IntelliJ IDEA Community Edition version 12, to version 13 (updated to 13.0.1) and apparently the real-time ("on-the-fly") compilation of code does not work, at least not as found in other major IDEs (e.g., Eclipse).
A similar issue has been brought up in an earlier StackOverflow question and the answer was to check the corresponding option in File -> Settings -> Compiler, which I have of course done, but nothing changed.
The way it currently is, I can type whatever text in the Java code and there is no error highlighting, not even when the file is saved, let alone in real time.
Is there another setting or configuration that needs to be applied?
IntelliJ does something a lot better than compiling your files on the fly. It dynamically parses what you're typing, offering many more warnings than the java compiler produces. In comparison, compiling on the fly is a bad idea. Having said that, it sounds like you're having other problems, because you should have errors and other problems highlighted. At the top right of each editor window is a small coloured square. On good code it's green. It's yellow when there are warnings, and red when there are errors. If it's grey then Idea is analyzing your files. If you hover your mouse over the square it'll give you an idea about what Idea is doing, and how it's progressing. Try that before you try anything else. Idea never gets stuck, but it can run out of memory, if the analysis isn't progressing, then perhaps you've run out of memory, or have other issues, check this in the event log, which is at the bottom right of the window.
I've just been pulling my hair out over this working on my Mac in a coffeeshop running on battery power. Try File | Power Save Mode and make sure it's un-checked.

changing switches to "if-else" statements

I've just recently become interested in programming, and I want to create Android apps for phones or tablets. I've come a long way in a couple weeks from knowing almost nothing about java/xml. I'm very serious about this. I'm going to find the answer to this question one way or the other. In fact, I hope to have it figured out before anyone answers this. I've fixed many issues without resorting to asking anyone, but I've just been stuck on this issue too long. I figured I'd give this a shot.
I'm using an older tutorial to build a practice twitter app (the tutorials for these seem to be everywhere, which is why I chose it). I'm using Eclipse for an editor.
The following is an example of code from the tutorial. which relates to my question:
#Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.timeline);
Apparently since the intro of ADT 14, you can no longer use the (R.layout.timeline) phrase, which the error message refers to as a "switch statement."
Now, in a post I found on another site, someone who had a similar issue shows a screenshot of the "quick fix" in Eclipse using ctrl+1. in the screenshot, the fix that pops up says "convert switch to 'if-else' statement." This fix does not pop up in my version of Eclipse. My quick fix options are "migrate Android code", "create field 'timeline' in type 'layout'", "create constant 'timeline' in type 'layout'" or "rename in file."
If I choose "migrate Android code", a window pops up informing me of the ADT 14 update, and how switch statements are no longer allowed in library projects. It says to convert the switch statement to an "if-else" statement by pressing ctrl+1 for the quick fix, then choosing "switch to 'if-else' statement" like it does in the screenshot I found. But again, when I do this, that option does not pop up.
I would much rather know what needs to be changed in the code than know how to make the right quick fix pop up. If it isn't too much trouble, an explanation of why exactly these changes are affective would be very helpful. I have many (MANY) errors in my java files right now, but most of them are due to this exact problem in different forms. If I could see just one before/after example I could probably figure it out from there without an explanation. But after hours of searching, I cannot find that so far by googling.
Thanks so much in advance....
And for the record, I don't see any switch classes in any of my java files, if that makes a difference for the answer...
Make sure you click on the switch keyword itself then press Ctrl + 1.
This confused me at first as well...
If it still doesn't show up, what version of Eclipse are you using?
If you are using a Mac select the keyword switch and click Shift + Command + 1.
That will show a prompt to change switch to if else conditions.
I've been having the same issues. For me, I was switching on view.getId(). Before the switch, declare int id = view.getId();. Then switch in id. Then you can ctrl+1 click and the "Convert Switch to If/Else" should pop up.
They made this change to decrease the build speed. My projects now build in roughly 1/10th of the time. I'm glad I upgraded the ADT.
The issue happens because since ADT 14 resource identifiers are no longer final.
The quick solution you can change switch statements with if-else statements.
With Android Studio 4.1.3
Step:1. Just right click on the switch keyword of statement.
Step:2 Click on the first option Show Context Actions.
Step:3 Click replace switch with if.
Done
To me, it looks like you don't have a timeline resource.
Breaking down R.layout.timeline
R refers to Resources
layout refers to the collection of layouts in your application
and timeline refers the specific resource that you are trying to apply setContentView() too.
If my hunch is correct, you don't have the timeline resource.
Create a new XML file in your layout folder in eclipse and name it 'timeline'
That should resolve the issue.
I hope you got things working.
I agree that this sounds like some weird Eclipse error that is not what it seems, and not what Quick Fix says it is. Eclipse has been known to lie from time to time. Cleaning your project (as #Stephen Dubya said), cutting out the offending code, saving the file, pasting it back in, and saving again...these are some of the non-obvious tricks that sometimes get Eclipse to behave.
In general, I think it would be good for you to get more familiar with some of the Java basics like switch; I think it will make your learning of Android a lot easier. Although the tools and documentation keep improving, Android is still young and not always easy to learn using tutorials, especially when you aren't used to writing code at all or using complicated IDEs like Eclipse.
But I digress. It is only in Android library projects, not regular projects, that Android doesn't treat resources as constants (final variables), since ADT 14. That means means that in library projects, you can't use R.layout.timeline or similar resource variables in your switch statements. You can only switch on whole numbers or enum values.
Using if-else all the time may be your best bet, anyway. switch can, especially for beginners, lead to logic errors in your code, and anything you can write using switch can be rewritten using if-else blocks. Personally, I've stopped using switch in Android and other Java code altogether.
You need to place the curse right before the s in the word switch, and the press cmd 1 . If you switch statements have fall-through clauses, the option to convert won't be available.
Somehow I overworked this error. I have deleted my project from workspace. Reverted it's .project files to old ones commited at SVN. Then at Eclipse uninstalling ADT and install it again. Then import my project. - > Libraries are added the old way and as result all fields at R.java are now final. Hope this helps.

Eclipse Helios having performance problems Mac OS X 10.6.5

Short Story: My house was broken into MacBook Pro among stolen items. Bought a new MacBook restored from TimeMachine drive including Eclipse folder. System files could not be restored because hardware was slightly different. I did a system update and updated to 10.6.5 and Java 1.6.0_22, all the latest. I run Eclipse Helios for Java development for college assignments.
The problem I am having is that when I run Eclipse and start coding when I get to a method of any type when eclipse usually throws up an auto-complete type box underneath the current line the program hangs for a few seconds while it loads / moves through the list depending on how fast I am typing. Example:
JTextField txt = new JTextField();
txt.get....
I could type the second line out pretty quickly as I know what I am looking for but the program will hang (multicolor swirly mac icon will replace pointer). Eclipse process will spike to 100% and I will not be able to do anything until the auto-complete box finishes whatever it could possibly be doing and the suggestion moves down to "getText()" or whatever the list beginning with "get" contains.
Things I have done to correct include, re-downloading and installing eclipse into another location, creating a new workplace in that eclipse install, re-creating the projects and code files by hand (i.e. not importing anything). The problem still persist.
I am not seasoned enough in Java to abandon the helpful suggestion box, especially when I am learning new things.
Anyone else experience this problem or know a possible solution I have not tried?
This happens with me with Android development, and I have a clue as to why - documentation! If I uninstalled the documentation, meaning the completion list wouldn't show me any API documentation, the completion list was back up to normal speed. Installed it back, the completion list is slow again. This wasn't a problem in Galileo, just Helio.
I'm trying to find the best JVM settings to use with eclipse to see if I can improve things.

Categories

Resources