4 Replies - 5413 Views - Last Post: 25 May 2015 - 11:05 AM

#1 techncafn33   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 01-September 11

First Android App using Android Studio - XML error

Posted 24 May 2015 - 10:29 AM

I am using Android Studio for the first time, in an attempt to create an Android app used for a quiz. The visual representation of the app, in the preview section of Android Studio, looks okay. I am receiving an "Error parsing XML: mismatched tag" error message, which is associated with the RelativeLayout and LinearLayout elements. Thank you, in advance, for any assistance.



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
    android:background="@drawable/background"
    android:id="@+id/RelativeLayout">



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background2"/>

<!-- TextView elements here -->


    <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="26dp"
    android:paddingBottom="5dp"
    android:text="@string/version"
    android:textColor="#f7f9f6"
    android:textSize="13dp"
    android:textStyle="italic" />


<ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageButton"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:src="@drawable/quizimage"
            android:contentDescription="@string/quizimage"
            android:onclick="beginQuiz" />



<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="@string/button2003"
android:src="@drawable/button2003"
android:onclick="onclick2003"/>




</LinearLayout>

</RelativeLayout>




Is This A Good Question/Topic? 0
  • +

Replies To: First Android App using Android Studio - XML error

#2 techncafn33   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 01-September 11

Re: First Android App using Android Studio - XML error

Posted 24 May 2015 - 10:37 AM

I believe that I had found out the cause of that error after posting. I had not included the id reference for LinearLayout and have corrected it:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
    android:background="@drawable/background"
    android:id="@+id/RelativeLayout">



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background2"
    android:id="@+id/LinearLayout">


Was This Post Helpful? 0
  • +
  • -

#3 techncafn33   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 01-September 11

Re: First Android App using Android Studio - XML error

Posted 24 May 2015 - 11:29 AM

I am attempting to create an Android app by using Android Studio. The display of the app shown in the preview section of Android Studio looks okay. Compilation of the app fails and I receive 4 instances of the following error : "error: class, interface, or enum expected"

I also receive the following messages:

"Cannot resolve symbol 'activity_main'"
"Cannot resolve symbol 'menu_main'"
"Cannot resolve symbol 'action_settings'"
"Class or interface expected", which is associated with
import android.widget.Toast;



I had initially received a "Cannot resolve symbol R" error, so I used [import android.R] to import the R class.

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.R;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }}

import android.widget.Toast;

    public void onclick2003 (View view)
    {
        Toast.makeText(this, "Correct!", Toast.LENGTH_SHORT).show();
    }




I have done some research and have found that posts in some forums suggest that the errors that I am receiving could be due to a corrupt XML file. I have recently, at least seemingly, corrected an issue that I had with the XML, which can be viewed here
Was This Post Helpful? 0
  • +
  • -

#4 xclite   User is online

  • I wrote you an code
  • member icon


Reputation: 1364
  • View blog
  • Posts: 4,187
  • Joined: 12-May 09

Re: First Android App using Android Studio - XML error

Posted 24 May 2015 - 06:53 PM

Can you post the actual error?

Edit: Nevermind. This isn't a valid Java file.

Why do you have the stray import and method onclick2003 at the bottom?
Was This Post Helpful? 0
  • +
  • -

#5 AKMafia001   User is offline

  • </code.in.dream>
  • member icon

Reputation: 238
  • View blog
  • Posts: 738
  • Joined: 11-June 11

Re: First Android App using Android Studio - XML error

Posted 25 May 2015 - 11:05 AM

Topics Merged...

You should be using YourPackageName.R instead of android.R. If you receive an error about R not being resolved there might be an error in one of your resource files which is preventing the R file from being generated. Make sure you don't have an error in your resource files.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1