New line (\n) in Android XML. Android 4.1 SDK Compatibility issue? - android

I faced this strange problem.
On my layout xml, I have a single TextView, and in it I have the following text:
"Welcome to App.\n etc" , defined in strings.xml.
In a tablet running 4.0 displays the full string.
In a smartphone running 2.3.7 it displays just before the \n.
On previous apps I have created, \n worked okay.
Anybody faced something similar?
XML Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textViewWelcomeNotes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_centerHorizontal="true"
android:layout_centerVertical="false"
android:layout_margin="15dp"
android:layout_marginTop="20dp"
android:fitsSystemWindows="false"
android:focusableInTouchMode="true"
android:gravity="center_vertical|center_horizontal"
android:hint="#string/msgWelcomeNotesHint"
android:paddingTop="10dp"
android:text="#string/msgWelcomeNotes"
android:textSize="14dp" />
</RelativeLayout>

It was a weird bug of latest ADT 20.0, in Eclipse Juno.
I made a fresh install of Eclipse Juno, because i heavily loaded it with plugins,
and now \n appears okay, in the same apk, on 2.3 and 4.0+ Android Versions.
Also some other bugs, eg when creating new activity (New->Other->Android Activity), exist on this ADT.

Related

Android Studio Beta 1.2 issue formatting xml-layout

Recently I’ve upgraded from Android Studio 1 to Android Studio Beta 1.2.
And among other issues, it seems that the shortcut (Option + Command + L) for formatting the xml-layouts it doesn’t reorganice code any more.
In the previous version of Android Studio, if you had something like this:
<RelativeLayout
android:layout_alignParentLeft="true"
android:layout_margin="#dimen/_10dp"
android:id="#+id/rl_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
After formatting you got the next result:
<RelativeLayout
android:id="#+id/rl_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="#dimen/_10dp">
But now I just get this message: “No lines changed. Code is already properly formatted”
Is there any kind of configuration that I’m missing it?
Thanks!
Try Ctrl+Shift+Alt+L, you should have a dialog where you can tick "Rearrange".

Error while adding text field in Emulator

Whenever I add any TextView in the XML file it shows me the error "Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V".
What is the reasoning behind this?
This is the XML part where the above written error is being shown.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
Check the "Android version to use when rendering layouts". Chose any version that does not have "W" at the end . Those versions are for wearable devices.
This problem happened on API 20 (Android 4.4 W). Problem will be solved by changing Android version to use for rendering level form API 20 (Android 4.4 W) to API 19 (Android 4.4.2) (android icon in top right corner of graphical layout) or update your SDK to Android L (API 20 L preview)
Source of answer

parseSdkContent failed Could not initialize class android.graphics.Typeface

When I open layout editor, eclipse is giving this error:
parseSdkContent failed
Could not initialize class android.graphics.Typeface
And when I try to run project, it is giving this error :
An internal error occurred during: "Launching myapp".
java.lang.NullPointerException
Every time I'm getting this error and I have to restart eclipse. Is there any solution? This problem started suddenly today.
XML file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66000000"
>
<RelativeLayout
android:id="#+id/refresh_match_layout"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_centerInParent="true"
android:layout_margin="15dp"
android:background="#drawable/app_detay_lay_bg"
android:orientation="vertical"
android:padding="10dp"
android:visibility="visible" >
<ImageView
android:id="#+id/app_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="10dp"
android:textColor="#ffffff"
android:textSize="20sp" />
<TextView
android:id="#+id/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:textColor="#000000"
android:layout_toRightOf="#+id/app_icon"
android:layout_marginTop="2dp"
android:textSize="20sp" />
<ImageButton
android:id="#+id/app_detail_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="2dp"
android:background="#null"
android:src="#drawable/settings_detail"/>
<ImageButton
android:id="#+id/app_remove_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/app_icon"
android:layout_alignTop="#+id/app_detail_button"
android:background="#null"
android:src="#drawable/settings_remove" />
</RelativeLayout>
</RelativeLayout>
Error picture:
I deleted the home/.android folder and everything is normal now.
In Windows you can find this folder in C:/Users/User/
Source: https://stackoverflow.com/a/5883841/3681056
Note: it happens when you have 2 versions of SDK and eclipse, both in the same computer (and using the same .android file), if you open on version the other will get this error.
Deleting ".android" is temporarily fixing the problem with me as after sometime it begins to come again ..
Here is another cause and fix that might help .. This is happening because of existence of 2 versions of SDK in the same machine but in case you have only one version (probably it is 21) just download the SDK platform for API 20 (4.4W) as there is a problem in 21's "layoutlib.jar"). start applying the following:
Close Eclipse
Navigate to your sdk folder (something like C:\adt-bundle-windows-x86_64-20140321\sdk)
Go to platforms folder -> android-21 folder -> data folder and rename layoutlib.jar (for backup only)
Copy the same file (layoutlib.jar) from your android-20 folder to this folder "android-21"
Start Eclipse
deleting home/.android is useless, i delete ~/.android/avd it worked for me :)
I was getting this error too
parseSdkContent failed
Could not initialize class android.graphics.Typeface
But I could only resolve it after changing my Eclipse ADT from 64 bit to 32 bit on Windows 7 64 bit OS.

XML error - Doing Google Android NDK Lesson 1

The Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:weightSum="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="#+id/edit_message"
android:layout_weight = "1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:id="#+id/bSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
The error message:
BUILD FAILED
C:\My First App\res\layout\activity_main.xml:7: Unexpected element "{}LinearLayout" {antlib:org.apache.tools.ant}LinearLayout
The code is almost exactly the same as the code on the Android website and it's really frustrating that I can't seem to get it to work. Is the problem in the code, or is it on my side? I am using Eclipse
I was getting the same error. I was using Indigo in Ubuntu 12.04, and no matter what libraries I got or eclipse plugins I used it was always there.
What worked for me was re-downloading and reinstalling the Android SDK (probably not necessary in your case), and downloading Eclipse Classic (Juno) from the Eclipse website rather than using the Indigo package that was in the repos. The lesson said Classic was recommended anyway, so whatever, I'm just happy it works now.
If you are using Windows, I'd still suggest downloading the most recent Classic version, but otherwise I can't be of help there.

android: no resource found at #string

My android app is complaining about resource missing, which I do think has been included and worked great in previous version of android.
e.g.,
menu.xml:27: error: Error: No resource found that matches the given name (at 'title' with value '#string/lookup_about').
<item
android:id="#+id/about"
android:title="#string/lookup_about"
android:icon="#drawable/ic_menu_help"/>
In string.xml, I've defined
<string name="lookup_about">About</string>
Update:
I found that in one case, only the 2nd #string/spinder_prompt was complained by eclipse. The first one is not
<TextView
android:id="#+id/refresh"
android:text="#string/spinder_prompt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="16dip"
android:typeface="sans"
android:layout_gravity="left"
android:textColor="#ffffff"
/>
<Spinner android:id="#+id/Spinner01"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:prompt="#string/spinder_prompt"
android:layout_weight="0.02"/>
In my strings.xml,
<string name="spinder_prompt">Choose the number of items to show</string>
FYI. This code was built and deployed and tested on Android 2.2 systems without any issues.
Problem solved. The reason is due to the upgrade from 2.1-> 3.0. The automatically generated R.java cannot update itself, one has to "edit" that file and save it. Then problem solved. Developers are experiencing similar issues...http://www.coderanch.com/t/466092/Android/Mobile/android-eclipse

Categories

Resources