Im new as a developer of Android apps. I find a problem. that is R.layout.main cannot be resolved. How can I solve my problem. my code is here. please solve my problem.
package com.android;
import android.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class HelloActivity extends Activity {
/** Called when the activity is first created. */
Button bt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt=(Button)findViewById(R.id.ButtonOk);
bt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Toast.makeText(getBaseContext(), "Welcome Android World", 3000).show();
Intent intent = new Intent(HelloActivity.this, DisplayActivity.class);
startActivity(intent);
}
});
}
}
*
and my xml code is here:
*
<?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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:id="@+id/ButtonOk" android:height="50dp" android:width="100dp"></Button>
</LinearLayout>
Step 1 : Remove import android.R;
Step 2 : Clean And Rebuild
(It should work)
If not
Then close the project
exits eclipse and open again. Follow the steps it should work.
If not
Change your package
From
import android.R;
To
import yourpackage.R;
It Should work
Remove the line import android.R from the header.
and do a Ctrl + Shift + O
If android.R appears again, then manually write
import <yourpackagename>.R
Looks like you used the package name as com.android.R. Ideally speaking, avoid using package names like com.android. Try to maintain it like com.companyname.appname
So you get into that habit, and don't have the pain of changing the package name in all the folders once you are about to publish.
Import com.android.R not android.R because your package name is com.android
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With