Android 1.5-specific error - android

I am having trouble with with getting my application to function on android 1.5. It works fine in 1.6, 2.1, and 2.2 but whenever I attempt to run it in 1.5, I get an immediate force close with the LogCat output:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.qrohlf.activites/com.qrohlf.activites.BookmarkHistoryTabActivity}:
android.view.InflateException: Binary XML file line #2: Error inflating class
java.lang.reflect.Constructor
This strikes me as very odd, as line #2 of my layout XML is just
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Any ideas? Is there some major API change between 1.5 and 1.6 in the way layout XMLs are done that I'm missing?
(I've included the rest of my layout xml below for reference)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include android:id="#+id/custom_titlebar" layout="#layout/custom_titlebar" />
<ViewFlipper android:id="#+id/frame_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ListView android:id="#+id/soccerteams_listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF"/>
<ListView android:id="#+id/countries_listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF"/>
</ViewFlipper>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:background="#android:color/black"
android:padding="0px">
<Button android:id="#+id/bookmarks_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/bookmarks"
android:textColor="#android:color/primary_text_dark"
android:drawableTop="#drawable/ic_bookmark_tab"
android:background="#drawable/tab_background"
android:layout_weight="1"/>
<Button android:id="#+id/history_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/history"
android:textColor="#android:color/primary_text_dark"
android:drawableTop="#drawable/ic_history_tab"
android:background="#drawable/tab_background"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>

Please ensure you have al required drawables in "drawable" directory. 1.5 doesn't understand "drawable-hdpi" directory and others, it only knows "drawable".

Related

Unknown Error in XML

Hi i have made this xml file but it is throwing some error : Incorrect line ending: found carriage return (\r) without corresponding newline (\n)
Here is my XML file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/help_new_session"
android:layout_above="#+id/buttonHideNewSessionHelp"
/>
<Button
android:id="#+id/buttonHideNewSessionHelp"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:onClick="onButtonClick"
android:text="Hide" />
</RelativeLayout>
</LinearLayout>
The below process will resolve your issue.
Open layout file
Ctrl+Shift+F
Save the layout file and close it.
Delete any .out files the builder might have created(you can see .out files below the original layout file).
Clean project.
Try this layout Now
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/help_new_session"
android:layout_above="#+id/buttonHideNewSessionHelp"/>
<Button
android:id="#+id/buttonHideNewSessionHelp"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:onClick="onButtonClick"
android:text="Hide" />
</RelativeLayout>
</LinearLayout>
It is looking perfect
I use the same code of your not giving any problem to me.Select complete xml and use ctrl+i i will align and clean the project once

"No resource found" When using <include layout="">

In my project I have created a global header layout global_header.xml and I use it in all of my layout XML files by using <include layout="#layout/global_header.xml">.
I have used this method before, and I am currently using it in this project. My problem is that I have a layout with the following contents:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF" >
<include layout="#layout/global_header" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/global_header">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Contents of global_header.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/global_header"
android:layout_width="fill_parent"
android:layout_height="60sp"
android:layout_alignParentTop="true"
android:background="#FFDDDDDD" >
<ImageView
android:id="#+id/global_header_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5sp"
android:layout_marginTop="5sp"
android:adjustViewBounds="true"
android:src="#drawable/header" />
<View
android:layout_width="fill_parent"
android:layout_height="1sp"
android:layout_alignParentBottom="true"
android:background="#FF000000" />
</RelativeLayout>
And I am getting an error on android:layout_below="#global/header" saying that:
error: Error: No resource found that matches the given name (at 'layout_below' with value '#global/header').
I have used the include in other layouts in the project and it works without a problem, but for whatever reason, this layout file will not load the ID from the header where as all other layouts do.
The project will not build with this error even though I am sure that once running on the device it will find it not a problem, has anyone else had this problem? Is there solution/workaround?
Any and all help is greatly appreciated.
Try this, specify id for include layout and use
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF" >
<include layout="#layout/global_header" android:id="#+id/header"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/header">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</RelativeLayout>
</ScrollView>
Hope both xml (main.xml & global_header.xml) is exist in your layout folder within resources.
kindly clean the project and restart your eclipse, it works.
Note# I checked your xmls I didn't got any error.

Another r cannot be resolved to a variable/error parsing xml junk after document element

I know this is asked a lot but I got error parsing xml junk after document element problem and then after while of looking for the problem I got 10 r can not be defined errors i think it all resulted from the first error. But even when I remove the problem paragraph and click clean the error red x is still there on a blank area.The error started on the textview line at the bottom.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="25dp" >
<EditText
android:id="#+id/etCommands"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Type a Command"
android:password="true" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >
<Button
android:id="#+id/bResults"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="20"
android:text="Try Command" />
<ToggleButton
android:id="#+id/tbPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="80"
android:checked="true"
android:paddingBottom="10dp"
android:text="ToggleButton" />
</LinearLayout>
<TextView
android:text="invalid"
android:id="#+id/tvResults"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" />
should be
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >
Notice no / at the end of the tag. The / at the end is xml for "close this tag right now please." As it stands, you have invalid xml with two open tags for LinearLayout but closing LinearLayout 3 times.
It's hard to know what is the problem when you don't provide the full xml file. You probably forgot to close one of your LinearLayout items.
edit:
simply delete the / character from your LinearLayout declaration:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >

Android Java Coding Errors, Need Assistance

I am a beginner coder trying to learn how to make android apps. I am using these tutorials and I guess I have ran into an error.
Here is my text.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="25dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/etCommands"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Type a command"
android:password="true" />
<LinearLayout
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
<Button
android:layout_weight="20"
android:id="#+id/Bresults"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button" />
<ToggleButton
android:layout_weight="80"
android:id="#+id/tbPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:checked="true" />
</LinearLayout>
<TextView
android:id="#+id/tvresults"
android:paddingBottom="10dp"
android:checked="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="invalid" />
</LinearLayout>
I am getting an error next to where it says button. The error says:
Multiple annotations found at this line: - Element type "LinearLayout" must be followed by either attribute specifications, ">" or "/>". - error:error parsing XML:not well-formed (invalid token)"
You need to close the tag on your second Linear Layout >
<LinearLayout
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <!-- here -->
The colorcoding in your post already highlights the issue. You forgot the > after the LinearLayout opening tag.
The IDE is complaining that your xml is not well-formed. If the IDE's errors are not clear enough, you try an online validator such as http://www.xmlvalidation.com/ .

Adding a ListView causes the Android App to crash

I have a problem which seems to weird.
The Android application I created is running fine, but when I added a "ListView" element in my layout.xml file.
and I still haven't used the ListView in my java class the application refuses to startup.
It simply craches and gives me this Msg : The application Client (process com.example) has stopped unexpectedly. Please try again.
This is my layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="#+id/view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/filename"/>
<ListView android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
/>
<EditText
android:id="#+id/input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
/>
<Button
android:id="#+id/connect"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Connect"
android:onClick="Connect"
/>
<Button
android:id="#+id/download"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Download"
android:onClick="Download"
/>
<Button
android:id="#+id/delete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="List"
android:onClick="List"
/>
</LinearLayout>
Note: I'm testing on an Android device and not the emulator
Here is a Screenshot of the error I get in logcat: http://img852.imageshack.us/i/screenshotgg.png/
And finally found the sill mistake which caused it not to work
I declared 2 widgets with the same id.
Thnx alot in advance.
You need to close the LinearLayout. Add </LinearLayout> to the end of the xml.
Edit: I see that you've uploaded the log. The problem is in your onCreate-method on line 42. Please post this method.

Categories

Resources