I have been reading this tutorial -
http://developer.android.com/training/basics/firstapp/building-ui.html
and I got a problem... In the tutorial they explain the XML elements (TextField and Button) and in the end they say how to tun the program to see the button + the text field.
The problem is, that the emulator doesn't show them.. just a black screen.
I guess it's because I haven't added anything to the .java main file, but in the tutorial nothing was mentioned about it.
What should I do?
Thanks a lot for everyone who will help!
Asked
Active
Viewed 153 times
0

Roni Copul
- 183
- 1
- 1
- 8
-
What are the contents of the main Java file? It should, by default, have an `onCreate` method with a `setContentView(...)` call. If it doesn't, that'll be what's missing... – Cat Jul 07 '12 at 21:42
-
@RoniCopul Edit your question and add the code here, instead of trying to put it in a comment. – David Conrad Jul 07 '12 at 22:44
-
@DavidConrad I sent a link to the code below the answer (one of the last comments) – Roni Copul Jul 07 '12 at 22:50
1 Answers
0
If your XML file name is main.xml
then to display it content you need this method
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

vasart
- 6,692
- 38
- 39
-
Thanks, but it's still not working... I don't know what's the problem – Roni Copul Jul 07 '12 at 21:47
-
-
adding the code is a mess in a comment (because the
tag can't be used :/) so I'll just say that he code is the same as you said
– Roni Copul Jul 07 '12 at 21:57 -
Yep, the code looks good. What about `activity_main.xml`? Have you added the elements there or to another file? – vasart Jul 07 '12 at 22:00
-
My main XML file is activity_main.xml,(found in res/layout) and it's also uses a strings.xml file, that found in values/values – Roni Copul Jul 07 '12 at 22:05
-
-
If your XML file is `activity_main.xml`, try using `setContentView(R.layout.activity_main);` instead. – Cat Jul 07 '12 at 22:15
-
@vasart Only one.. But something weird error showed up in the console, I think it may be because the string.xml and activity_main.xml are in different directories – Roni Copul Jul 07 '12 at 22:17
-
-
`activity_main.xml` is a layout and it should be in `res/layout` folder. And `strings.xml` is a values file and it should be in `res/values`. – vasart Jul 07 '12 at 22:19
-
-
Main.java - http://pastebin.com/1KYdz4EJ
XML files - http://pastebin.com/cAUf17RV – Roni Copul Jul 07 '12 at 22:31 -
You have an error in `activity_main.xml`. Button has property `layout_width` set to `wrap_cont*a*nt`, but should be `wrap_cont*e*nt` – vasart Jul 07 '12 at 22:36
-
Still not working.. I think the problem is in the VM, because when I press "Run" the Eclipse writes "Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/ref/FinalReference" – Roni Copul Jul 07 '12 at 22:43 -
(Until now I opened the emulator through the list by pressing "Start..." because it didn't work by the "Run" button) – Roni Copul Jul 07 '12 at 22:45
-
Have a look at comment formatting help http://stackoverflow.com/editing-help#comment-formatting – vasart Jul 07 '12 at 22:47
-
OK thanks, the error is: Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/ref/FinalReference – Roni Copul Jul 07 '12 at 22:52
-
Here the solution of your problem may be found http://stackoverflow.com/questions/9455236/eclipse-error-noclassdeffounderror-java-lang-ref-finalreference – vasart Jul 07 '12 at 22:54
-
He start with "Find Running configurations -> java application", and I didn't really understand where I'm supposed to Find "Running configuration".. – Roni Copul Jul 07 '12 at 23:02
-
-
Ahhh almost working! Huge thank you but still there's a little error.. "Error: Could not find or load main class Check" – Roni Copul Jul 07 '12 at 23:10
-
-
I guess no... Or I just can't find it? Because I didn't create one, but I supposed there's already one – Roni Copul Jul 07 '12 at 23:22
-
@vasart Are you here? I found the AndroidManifest.xml, I searched for something that mentions "Check" instead of "Main" but I didn't find.. – Roni Copul Jul 07 '12 at 23:41