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.
Related
I am learning xml and this is all the 'code' my app executes when I run it.When I hit run in android studio and I get the following message unfortunately 'my app has suddenly stopped' accompanied by the following error messages in the event log,
Emulator: Warning: QStandardPaths: XDG_RUNTIME_DIR points to non-existing path '/run/user/1000/snap.android-studio', please create
it with 0700 permissions. ((null):0, (null))
Emulator: pc_memory_init: above 4g size: 40000000
I have tried running the app on diferent virtual devices as well as my own android device.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<TextView
android:id="#+id/happy_birthday"
android:text="#string/birthday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"/>
<TextView
android:id="#+id/dear_ian"
android:layout_width="291dp"
android:layout_height="wrap_content"
android:layout_below="#id/happy_birthday"
android:layout_marginStart="-127dp"
android:layout_marginTop="3dp"
android:layout_toEndOf="#id/happy_birthday"
android:text="#string/ian"
android:textSize="30sp" />
<ImageView
android:src="#drawable/download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
tools:ignore="ContentDescription"/>
<TextView
android:id="#+id/from_dennis"
android:text="#string/dennis"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:textSize="30sp"/>
app should run but it does not
Your application is not working not because of this. What is written in the log is only a warning. You can correct this warning by creating the necessary folder. To do this, write in the terminal linux:
mkdir /run/user/1000/snap.android-studio
I stopped getting the Emulator: pc_memory_init: above 4g size: 40000000 error after decreasing the RAM on the AVD below 4G:
From the main menu, click: Tools > AVD Manager
Click the pencil icon (Edit this AVD) under Actions for the target Virtual Device.
Click Show Advanced Settings
Set RAM to a value less than 4G (for instance, 3072MB)
Click Finish, then Run your app!
Try:
From file menu: Invalidate cache and restart
Increase Android Studio memory limit
Run as Administrator
Also try posting the logcat / MainClass
I'm using data binding library and I experience following issues in Android Studio 3.0:
somelayout.xml:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="meeting"
type="some.package.MeetingStatusResponse"/>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#{meeting.title}"
tools:text="Title"
/>
...
</LinearLayout>
</layout>
In this place: android:text="#{meeting.title}" Android Studio 3.0 underlines the # symbol and informs about error:
Error:(29, 27) <expr> or <lambda expression> expected, got '#'
Model class is written in Kotlin if it has any relevance.
The code completion is also not working for bound classes. The application can be successfully build using both, gradle command and Android Studio run app button. So this is just editor issue.
I observe this issue on Mac. On Windows it works ok. I do not have more computers to check if it's platform related issue.
Maybe you forgot to add in gradle compileOptions ?
`sourceCompatibility JavaVersion.VERSION_1_7`
`targetCompatibility JavaVersion.VERSION_1_7`
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".
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.
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.