当我导入时,android.R
我得到 Error_1 并且 Error_2 已解决。那么,我该如何解决 Error_1。我试过改变import android.R
--> import com.example.testing.R
。但是它仍然无法正常工作。
甚至我的 login.xml 似乎也被找到了。没有错误。我也尝试过清理项目。仍然没有任何反应。
登录活动.java
package com.example.testing;
import android.R; //Error_1 : Don't include android.R here; use a fully qualified name for each usage instead
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class LoginActivity extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//setting default screen to login.xml
setContentView(R.layout.login); //Error_2 : login cannot be resolved or is not a field
TextView registerScreen = (TextView) findViewById (R.id.link_to_register);
//Listening to register new account link
registerScreen.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
//Switching to Register Screen
Intent i = new Intent(getApplicationContext(), RegisterActivity.class);
startActivity(i);
}
});
}
}
这是我的 login.xml
登录.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
<LinearLayout android:id="@+id/header"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@layout/header_gradient"
android:paddingTop="5dip"
android:paddingBottom="5dip">
</LinearLayout>
<!-- Footer -->
<LinearLayout android:id="@+id/footer"
android:orientation="horizontal"
android:contentDescription="@string/description"
android:layout_width="fill_parent"
android:layout_height="90dip"
android:background="@layout/footer_repeat"
android:layout_alignParentBottom="true">
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:layout_below="@id/header">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="@string/name" />
<EditText android:id="@+id/editText1"
android:hint="@string/edit_message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:layout_marginBottom="20dip"
android:singleLine="true"/>
<!-- Password Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="@string/password"/>
<EditText android:id="@+id/editText2"
android:hint="@string/edit_message1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:inputType="textVisiblePassword"/>
<Button android:id="@+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/login"/>
<TextView android:id="@+id/link_to_register"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:layout_marginBottom="40dip"
android:text="@string/loginDesc"
android:gravity="center"
android:textSize="20sp"
android:textColor="#0b84aa"/>
</LinearLayout>
<!-- Login Form Ends -->
</RelativeLayout>
</ScrollView>