Java 祝酒辞的两难处境

Java 祝酒辞的两难处境,java,android,Java,Android,我正在开发一个简单的应用程序,用户将必须填写他们的姓名、电子邮件、评价应用程序,并描述他们的体验(可选)。如果他们的字段为空(姓名和电子邮件),则会弹出一条错误消息。代码末尾的Toast.LENGTH\u LONG()有问题。它一直在说“需要方法调用” MainActivity.java @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

我正在开发一个简单的应用程序,用户将必须填写他们的姓名、电子邮件、评价应用程序,并描述他们的体验(可选)。如果他们的字段为空(姓名和电子邮件),则会弹出一条错误消息。代码末尾的
Toast.LENGTH\u LONG()
有问题。它一直在说“需要方法调用”

MainActivity.java

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

    Spinner spinner = (Spinner) findViewById(R.id.spinner1);

    //Create an array adapter
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.rate_array, android.R.layout.simple_spinner_dropdown_item);

    //Specify the layout for the drop down menu 
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    //Apply the adapter to the spinner
    spinner.setAdapter(adapter);

    final EditText name = (EditText) findViewById(R.id.Name);
    final EditText e_mail = (EditText) findViewById(R.id.email);
    final Button submit = (Button) findViewById(R.id.submit);

    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(name.getText().length() == 0){
                name.setError("Please fill in your name");
            }
            else{
                if(e_mail.getText().length() == 0){
                    e_mail.setError("Please fill in your email");
                }
                else{
                    Toast.makeText(this, "Validation successful", 
                    Toast.LENGTH_LONG()).show();
                }
            }
        }
    });

 }
}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
微调器微调器=(微调器)findViewById(R.id.spinner1);
//创建阵列适配器
ArrayAdapter=ArrayAdapter.createFromResource(这个,R.array.rate\u数组,android.R.layout.simple\u微调器\u下拉菜单\u项);
//指定下拉菜单的布局
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
//将适配器应用于微调器
旋转器。设置适配器(适配器);
最终EditText名称=(EditText)findViewById(R.id.name);
最终EditText电子邮件=(EditText)findViewById(R.id.email);
最终按钮提交=(按钮)findViewById(R.id.submit);
submit.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
if(name.getText().length()==0){
name.setError(“请填写您的姓名”);
}
否则{
if(e_mail.getText().length()==0){
e_mail.setError(“请填写您的电子邮件”);
}
否则{
Toast.makeText(此“验证成功”,
Toast.LENGTH_LONG()).show();
}
}
}
});
}
}
活动\u main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.infinite_space.myapplication.MainActivity"
android:orientation="vertical"
android:weightSum="1">

<TextView
    android:id="@+id/textView"
    android:layout_width="292dp"
    android:layout_height="37dp"
    android:text="Enter Feedback details to b sent to the developers"
    android:visibility="visible"
    tools:layout_editor_absoluteX="16dp"
    tools:layout_editor_absoluteY="16dp"
    android:layout_weight="0.18" />

<EditText
    android:id="@+id/Name"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="Your Name"
    android:inputType="textPersonName"
    tools:layout_editor_absoluteX="16dp"
    tools:layout_editor_absoluteY="67dp" />

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="fill_parent"
    android:layout_height="35dp"
    android:background="@android:drawable/btn_dropdown"
    android:spinnerMode="dropdown"
    tools:layout_editor_absoluteY="176dp"
    tools:layout_editor_absoluteX="16dp"
    android:prompt="@string/rate_level"
    android:entries="@array/rate_array" />

<EditText
    android:id="@+id/email"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="Your email"
    android:inputType="textEmailAddress"
    tools:layout_editor_absoluteX="16dp"
    tools:layout_editor_absoluteY="122dp" />

<EditText
    android:id="@+id/details"
    android:layout_width="fill_parent"
    android:layout_height="103dp"
    android:ems="10"
    android:hint="Details..."
    android:inputType="text"
    tools:layout_editor_absoluteX="16dp"
    tools:layout_editor_absoluteY="227dp" />

<CheckBox
    android:id="@+id/checkBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Would you like an email respond ?"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="343dp" />

<Button
    android:id="@+id/submit"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Send Feedback"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="385dp" />
</LinearLayout>


Toast.LENGTH\u LONG
是一个(常量)字段,而不是一个方法。将
LENGTH\u LONG()
更改为
LENGTH\u LONG
Toast。LENGTH\u LONG
是一个(常量)字段,而不是一个方法。将
LENGTH\u LONG()
更改为
LENGTH\u LONG
长时间
LENGTH\u LONG
或短时间
LENGTH\u SHORT
。去掉
LENGTH\u LONG
之后的()

长时间应为
LENGTH\u LONG
,短时间应为
LENGTH\u SHORT
。去掉
LENGTH\u LONG
之后的()

试试这个:

 Toast.makeText(this, "Validation successful",Toast.LENGTH_LONG).show();
试试这个:

 Toast.makeText(this, "Validation successful",Toast.LENGTH_LONG).show();

解决它;我需要更改Toast.makeText(这是“验证成功”,Toast.LENGTH_LONG()).show();Toast.makeText(MainActivity.this,“验证成功”,Toast.LENGTH_LONG.show();解决它;我需要更改Toast.makeText(这是“验证成功”,Toast.LENGTH_LONG()).show();Toast.makeText(MainActivity.this,“验证成功”,Toast.LENGTH_LONG.show();