-1

In my android application, I had create a simple application, in eclipse by file>project>Androiapp I had put down simple activity, but the application gives error.

Layout File

<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"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />

</RelativeLayout>

Code file

package com.example.testapp;

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

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.activity_main, menu);
        return true;
    }

}

As I can see there is no error in this code, but in eclipse it still generate error at setContentView(R.layout.activity_main); and getMenuInflater().inflate(R.menu.activity_main, menu);.

I think resource file is not loading

Note that I had not made any changes in auto generated code.

Sagar Upadhyay
  • 819
  • 2
  • 11
  • 31

4 Answers4

2

Remove this line.

import android.R;

and Clean the project and then build it.

Ajay S
  • 48,003
  • 27
  • 91
  • 111
  • I had removed `import android.R;` statement, and than I clean the project form **project?Cleanproject**, but still it gives msg that your project contain error... – Sagar Upadhyay Feb 24 '13 at 06:45
  • @Sagar Upadhyay then there is some thing another problem and could you post the error message. – Ajay S Feb 24 '13 at 06:45
  • Error **Description Resource Path Location Type Error executing aapt. Please check aapt is present at D:\Android\SDK\platform-tools\aapt.exe testApp Unknown Android Packaging Problem** I think this file is missing, that's why it generate an errors... – Sagar Upadhyay Feb 24 '13 at 06:50
  • Check these links http://stackoverflow.com/questions/4386392/aapt-not-found-under-the-right-path and http://stackoverflow.com/questions/7198905/how-to-diagnose-error-executing-aapt-error-in-eclipse and more google it for this. – Ajay S Feb 24 '13 at 06:58
0

Answer is

In your import

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

Remove this line

import android.R;
Subburaj
  • 5,114
  • 10
  • 44
  • 87
0

Could you remove this :

import android.R;

This would import the default resources bundle but you would want to import your local resources bundle. Since you are loading the activity you wouldnt need the local resources to be imported.

You could refer to any of these :

Android Eclipse Error "Android Packaging Problem"

Android Packaging Problem: resources.ap_ does not exist

https://groups.google.com/forum/?fromgroups=#!topic/android-developers/BvO5g6RMamo

Community
  • 1
  • 1
lokoko
  • 5,785
  • 5
  • 35
  • 68
0

Wild guess here: if you have an error in another XML file, then maybe this could block the creation of the auto-generated R file. Look under the gen folder and verify that the R.java file is there and well formed.

SylvainL
  • 3,926
  • 3
  • 20
  • 24