字符串不能得到解决或不是一个领域? [英] String cannot be resolved or is not a field?

查看:111
本文介绍了字符串不能得到解决或不是一个领域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有一个登录,并签署了code的解析。我正在关闭此教程。我有:

Basically I have a login and sign up code for Parse. I'm working off of this tutorial. I have:

LoginSignupActivity.java

LoginSignupActivity.java

 package com.androidbegin.parselogintutorial;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.parse.LogInCallback;
import com.parse.ParseException;
import com.parse.ParseUser;
import com.parse.SignUpCallback;

public class LoginSignupActivity extends Activity {
// Declare Variables
Button loginbutton;
Button signup;
String usernametxt;
String passwordtxt;
EditText password;
EditText username;

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get the view from main.xml
    setContentView(R.layout.main);
    // Locate EditTexts in main.xml
    username = (EditText) findViewById(R.id.username);
    password = (EditText) findViewById(R.id.password);

    // Locate Buttons in main.xml
    loginbutton = (Button) findViewById(R.id.login);
    signup = (Button) findViewById(R.id.signup);

    // Login Button Click Listener
    loginbutton.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            // Retrieve the text entered from the EditText
            usernametxt = username.getText().toString();
            passwordtxt = password.getText().toString();

            // Send data to Parse.com for verification
            ParseUser.logInInBackground(usernametxt, passwordtxt,
                    new LogInCallback() {
                        public void done(ParseUser user, ParseException e) {
                            if (user != null) {
                                // If user exist and authenticated, send user to Welcome.class
                                Intent intent = new Intent(
                                        LoginSignupActivity.this,
                                        Welcome.class);
                                startActivity(intent);
                                Toast.makeText(getApplicationContext(),
                                        "Successfully Logged in",
                                        Toast.LENGTH_LONG).show();
                                finish();
                            } else {
                                Toast.makeText(
                                        getApplicationContext(),
                                        "No such user exist, please signup",
                                        Toast.LENGTH_LONG).show();
                            }
                        }
                    });
        }
    });
    // Sign up Button Click Listener
    signup.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            // Retrieve the text entered from the EditText
            usernametxt = username.getText().toString();
            passwordtxt = password.getText().toString();

            // Force user to fill up the form
            if (usernametxt.equals("") && passwordtxt.equals("")) {
                Toast.makeText(getApplicationContext(),
                        "Please complete the sign up form",
                        Toast.LENGTH_LONG).show();

            } else {
                // Save new user data into Parse.com Data Storage
                ParseUser user = new ParseUser();
                user.setUsername(usernametxt);
                user.setPassword(passwordtxt);
                user.signUpInBackground(new SignUpCallback() {
                    public void done(ParseException e) {
                        if (e == null) {
                            // Show a simple Toast message upon successful registration
                            Toast.makeText(getApplicationContext(),
                                    "Successfully Signed up, please log in.",
                                    Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(getApplicationContext(),
                                    "Sign up Error", Toast.LENGTH_LONG)
                                    .show();
                        }
                    }
                });
            }

        }
    });

}
}

和我loginsignup.xml:

And my loginsignup.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="10dip" >

    <TextView
        android:id="@+id/txtusername"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/Username" />

    <EditText
        android:id="@+id/username"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtusername"
        android:inputType="text" />

    <TextView
        android:id="@+id/txtpassword"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/username"
        android:text="@string/Password" />

    <EditText
        android:id="@+id/password"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtpassword"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/login"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/password"
        android:text="@string/LoginBtn" />

    <Button
        android:id="@+id/signup"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/login"
        android:text="@string/SignupBtn" />

</RelativeLayout>

当我尝试运行它,我得到字符串不能得到解决,或者不是一个领域。 (字符串被用作一个占位符)。我的童话新Android开发。任何帮助将是巨大的。

When I try to run it I get "string cannot be resolved or is not a field." (String is used as a placeholder). I'm fairy new to Android development. Any help would be great.

推荐答案

而不是 -

setContentView(R.layout.main);

写这篇文章 -

write this-

setContentView(R.layout.loginsignup);

这篇关于字符串不能得到解决或不是一个领域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆