Android activity cannot be resolved or is not a field

I am a beginner in Android. This error occurs when I try to run my application“

activity_prima cannot be resolved or is not a field PrimaActivity.java  /esempio3/src/com/example/esempio3  line 19 Java Problem ".  
and also "activity_seconda cannot be resolved or is not a field SecondaActivity.java    /esempio3/src/com/example/esempio3  line 11 Java Problem"

I have put my activities in manifest.xml, but there is something wrong because my r.txt often disappears. This is my java and XLM files

This is my first active java file

package com.example.esempio3;

import android.R;
import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.app.Activity;

public class PrimaActivity extends Activity {

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

Button bottone= (Button)findViewById(R.id.bott1);
bottone.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view) {
     Intent intent = new Intent(PrimaActivity.this,       SecondaActivity.class);
     startActivity(intent);      
     finish();
}
});
}


}

This is my XML 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"
android:background="@drawable/sfondo1"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.esempio3.PrimaActivity" >


<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/img1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="27dp"
    android:src="@drawable/batman3" />


<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageView1"
    android:layout_marginTop="70dp"
    android:layout_centerInParent="true"
    android:text="Benvenuto nella mia App"
    android:textColor="#FFA07A" />




<Button
    android:id="@+id/bott1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="70dp"
    android:layout_below="@+id/img1"
    android:layout_above="@+id/bott2"
    android:layout_centerInParent="true"
    android:onClick="Login"
    android:text="Login" />

<Button
    android:id="@+id/bott2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="101dp"
    android:onClick="Registrati"
    android:text="Registrati" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:text="TextView" />

</RelativeLayout>

This is my second active java file

package com.example.esempio3;

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

public class SecondaActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_seconda);
}




}

My XML file is:

<?xml version="1.0" encoding="utf-8"?>
<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:background="@drawable/sfondo1"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.esempio3.SecondaActivity" >

<TableLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true">
<TableRow
    android:layout_marginTop="100dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#F5F5DC"
    android:text="Username:"/>
     <EditText
    android:layout_height="wrap_content"
    android:inputType="text"
    android:id="@+id/username" />
</TableRow>

 <TableRow
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#F5F5DC"
    android:text="Password:"/>
     <EditText
    android:layout_height="wrap_content"
    android:inputType="text"
    android:id="@+id/password" />
</TableRow>

 <TableRow
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#F5F5DC"
    android:text="Indirizzo email:"/>
     <EditText
    android:layout_height="wrap_content"
    android:inputType="text"
    android:id="@+id/mail" />
</TableRow>

 <TableRow
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#F5F5DC"
    android:text="Nome:"/>
     <EditText
    android:layout_height="wrap_content"
    android:inputType="text"
    android:id="@+id/nome" />
</TableRow>

</TableLayout>

 </RelativeLayout>

My list is

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.esempio3"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="21" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".PrimaActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
            <activity
        android:name=".SecondaActivity"
         >
    </activity>

</application>

Thank you for your help

resolvent:

You should import the R of the package, perhaps com.example.esempio3. R instead of Android. R. just change the following:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>