Error in XML Code?
So I just finished creating a new UI in DroidDraw (relativelayout throughout), and I've imported it into my main.xml file. The problem is, whenever I run "check for xml errors" the output return states "cvc-elt.1: Cannot find the declaration of element 'RelativeLayout'. [8]" It's really bothersome, and I think it's what's causing my app to force close on run (there are no errors in the actual code itself). I'm fairly new to the whole android dev scene, so it's entirely likely that this is supposed to happen and I'm just being stupid. In any case, here is the block of text in which the error is returned:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/widget31"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
</RelativeLayo开发者_C百科ut>
Any help would be much obliged.
Yeah, I don't believe any of the tag names are actually declared. Notice that you're importing the Android namespace as android
, so things prefixed with android:
are declared. Anything that's not prefixed with android:
isn't really being declared. This isn't a problem. Some would say it's a little sloppy of Google, since the XML won't validate, but the Android compiler doesn't have a problem with it.
So I think you need do start looking elsewhere for the reason your app crashes on startup. (Are you developing in Eclipse? Run in debug mode and/or watch LogCat.)
Incidentally, the reason that the element names aren't declared is because you can use your own. For example, if you write your own subclass of Button
with the fully qualified name com.mydomain.MyAmazingButton
, you can use it in your layouts like this:
<com.mydomain.MyAmazingButton android:layout_width="..." android:layout_height="..." />
Hope that helps.
精彩评论