我是个android开发新手。当我尝试运行我的应用程序时,出现此错误“

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"

我已经将我的活动放在manifest.xml中了,但是由于我的r.txt经常被取消外观,所以出现了一些问题。这里有我的Java和XLM文件。
这是我的第一个活动Java文件。
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();
}
});
}


}

这是我的xml文件。
<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>

这里是我的第二个活动Java文件。
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);
}




}

我的XML文件是:
<?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>

我的清单是
<?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>

提前谢谢你的帮助。

最佳答案

您应该导入包的r,可能是com.example.esempio3.R,而不是android.R。只需更改以下内容:
android -  Activity 无法解决或不是字段-LMLPHP

10-07 19:30
查看更多