So when I try to create a new project (any project type) eclipse just produces an error that says:
java.lang.NullPointerExeption
Any help is appreciated.
It would be much more helpful if you included as much detail about the issue as you can. Next time, put a little more effort when you ask for help, which includes doing more research. Based on what you gave, I found several sources in the first 5 links of a google search for Eclipse new project null pointer.
I'm going to try and format this well so that others who have the same issue have a nicely formatted reference.
Possible Solutions to Eclipse NullPointerException
From here. Might be the best resource to look at since Manjaro is based on archlinux, AND this thread is relatively new.
Transcription of user Misto's solution in case link goes dead:
Doesn't look familiar, but I've had my share of problems with SWT (Eclipse's widget toolkit) and GTK3, you can try forcing SWT back to GTK2 with the environment variable SWT_GTK3=0. Maybe this helps.
Other link(s) detailing the same problem:
Eclipse Forums, May 12th 2016
Transcription from user Felix Dorner:
Try this:
- Open the error log view. (Window->Show View->Error Log)
- Clean the log (there is double x in its toolbar)
- Create the project
- Double click on the error that should appear in the log
- Copy the contents of the stack trace dialog and paste here.
Felix
After the problem persists with another error exception, Felix again replies with this:
java.lang.NullPointerException
at
org.eclipse.swt.widgets.TabFolder.gtk_switch_page(TabFolder.java:570)
These two lines are sufficient for google to find you a solution ;)`
As the title says, how?
I have looked around the internet and found a bunch of answers saying to go to
Settings|Code|Code completion
but it seems that settings category is gone in version 14 of IntelliJ, which is the one I am using. The reason that it's off in the first place is because the teacher in my Java course has made his own custom code inspection .JAR-file, which when I installed it, turned my automatic code completion off. I have changed that profile back to the default one in every category of the settings that I have found so far, without results. Please help!
Check this option.
If it is not worked, check "keymap" option.
Maybe key was using for other action.
I am very new to Eclipse, java programming and well all "programming" in general and I have recently been learning how to use Eclipse. I've been using it for about a week now and it has been going decent so far. Apart from some errors,(mostly on my part) that has been fixable by restarting the program itself.
However when I started using it today I could no longer see the suggestions made from the Quick Fix command, for example if I type findVi and then press CTRL+1, it shows "No suggestions available" instead of "findViewById()" or something similar.
I know it's the correct binding, I even reset the keys to default to be sure. It still finds the ID if i type it manually but I would like to able to finish words faster that way.
If you guys got any suggestions that can help me out, please let me know.
Thanks.
- First of all if you are new with Java, and want to practice Java, you should NEVER USE ANY IDE, that way you learn the proper syntax, and it helps your error finding skills.
- But as you wrote "findViewById()" it seems that you are doing Android, Now this happens sometimes that Eclipse behaves weirdly with Android. Thats the reason when you make any changes into your Eclipse GUI while working with Android, its always better to see if those changes have taken effect.
- This problem usually goes off after closing and re-opening the Eclipse once or twice.
- Ok try this....
Type findVie then press Ctrl + Space-Bar See if the suggestion pops up...
You can access the Content Assist preferences from Window > Preferences > Java > Editor > Content Assist... perhaps something got messed up.
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.
When I press Ctrl-S to save my Java file in Eclipse it's jumping to the function name. This is very annoying. Someone know what to do about this?
Go to Window->Preferences->General->Keys (you can also search for Keys in the main Preferences window). You most likely have added a binding which makes eclipse jump to the function name when you press ctrl+s.
Another place to look is Window->Preferences->Java->Code Style->Clean Up and Window->Preferences->Java->Editor->Save Actions. That is where all actions are defined which happen when you save/clean up a document.
Try looking at your keyboard bindings. I certainly don't have this problem on either of my Eclipse installs. You might have Ctrl-S assigned to two different actions?
This was really annoying problem for me also.
Solved it by going to Preferences->General->Workspace and unchecking "Refresh on access" checkbox.
I had a similar problem with Ctrl+C malfunctioning in Eclipse.
Here is a similar question regarding it.
Maybe try upgrading to the latest version if the above solutions do not work.