Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中if语句大小写错误_Android - Fatal编程技术网

android中if语句大小写错误

android中if语句大小写错误,android,Android,好的,在我输入if语句之后,我在关闭制动器上得到了这个错误 包com.example.mohmed.king import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ImageButton; import android.widget.TextView; public class l1

好的,在我输入if语句之后,我在关闭制动器上得到了这个错误 包com.example.mohmed.king

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

public class l1 extends Activity {

    ImageButton ans;
    TextView text;

boolean check(){
    if (text.getText()=="")    
        return true;
    else
        return false;
};

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

        ans = (ImageButton) findViewById(R.id.imageButton);
        text = (TextView) findViewById(R.id.textView);
        ans.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
if(check()==true){

                Intent myIntent = new Intent(v.getContext(), MainActivity.class);
                startActivityForResult(myIntent, 0);
            }
                else
    text.setText("اجابة خاطئة");
            }`enter code here`
            );<----- here
        }<----- here
    }<----- here
}
改变

boolean check(){
    if (text.getText()=="")    
        return true;
    else
        return false;
};

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

    ans = (ImageButton) findViewById(R.id.imageButton);
    text = (TextView) findViewById(R.id.textView);
    ans.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
if(check()==true){

            Intent myIntent = new Intent(v.getContext(), MainActivity.class);
            startActivityForResult(myIntent, 0);
        }
            else
text.setText("اجابة خاطئة");
        }`enter code here`
        );<----- here
    }<----- here
}<----- here

此if text.getText==错误。使用if text.getText.toString.equals,相反,你不需要写ifcheck==true{extended。简单的ifcheck{就足够了。所有这些都是什么?至少你使用了v.getContext,对任何想知道的人来说都是错误的答案。
boolean check(){
    return "".equals(text.getText()))    
};


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

    ans = (ImageButton) findViewById(R.id.imageButton);
    text = (TextView) findViewById(R.id.textView);
    ans.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(check()){
                Intent myIntent = new Intent(v.getContext(), MainActivity.class);
                startActivityForResult(myIntent, 0);
            } else {
               text.setText("اجابة خاطئة");
            }
    });        
}