Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.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
Java 截击发球不';不要进入回调_Java_Android_Http_Android Volley - Fatal编程技术网

Java 截击发球不';不要进入回调

Java 截击发球不';不要进入回调,java,android,http,android-volley,Java,Android,Http,Android Volley,我正在尝试使用volley服务执行http请求,我发现了一个非常有用的答案,关于如何为不同的http请求组织服务,因此您不需要为每个请求都编写所有代码 请求工作正常,我得到了想要的结果,但它从未在mainActivity上进入取消回调 所以这永远不会被执行: void initVolleyCallback(){ mResultCallback = new IResult() { @Override public void notif

我正在尝试使用volley服务执行http请求,我发现了一个非常有用的答案,关于如何为不同的http请求组织服务,因此您不需要为每个请求都编写所有代码

请求工作正常,我得到了想要的结果,但它从未在mainActivity上进入取消回调

所以这永远不会被执行:

void initVolleyCallback(){
        mResultCallback = new IResult() {
            @Override
            public void notifySuccess(String requestType,JSONObject response) {
                Log.d("GJ","success");
            }

            @Override
            public void notifyError(String requestType,VolleyError error) {
                Log.d(TAG, "Volley requester " + requestType);
                Log.d(TAG, "Volley JSON post" + "That didn't work!");
            }
        };
    }
以下是我的主要活动:

public class Register extends AppCompatActivity {

    EditText usernameTxt;
    EditText passwordTxt;
    EditText emailTxt;
    RequestQueue queue;
    boolean formValid = false;
    VolleyService mVolleyService;
    IResult mResultCallback;
    static final String TAG = "request12";

    final String URL = "http://10.0.2.2:3000/register";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //hide status bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_register);

        initVolleyCallback();

        //inicialize queue with volley
        queue = Volley.newRequestQueue(this);

        //inicialize form fields
        usernameTxt = (EditText)findViewById(R.id.username);
        passwordTxt = (EditText)findViewById(R.id.password);
        emailTxt = (EditText)findViewById(R.id.email);

        //set text for developing stage
        usernameTxt.setText("afcosta5");
        passwordTxt.setText("moitarioavE10");
        emailTxt.setText("filipecosta_10@hotmail.com");

    }

    public void register(View view) {

        System.setProperty("http.keepAlive", "false");

        //get form data
        final String username = usernameTxt.getText().toString();
        String password = passwordTxt.getText().toString();
        String email = emailTxt.getText().toString();
        Log.d("email",String.valueOf(isValidEmail(email)));

        if (!isValidEmail(email)) {
            emailTxt.setError("Invalid Email");
        }

        //inicialize a map with pair key value
        final Map<String, String> params = new HashMap<String, String>();

        // Add form fields to the map
        params.put("username", username);
        params.put("email", email);
        params.put("password", password);

        JSONObject sendObj = new JSONObject(params);

        mVolleyService = new VolleyService(mResultCallback,this);

        mVolleyService.postDataVolley(URL,sendObj);



 void initVolleyCallback(){
        mResultCallback = new IResult() {
            @Override
            public void notifySuccess(String requestType,JSONObject response) {
                Log.d("GJ","success");
            }

            @Override
            public void notifyError(String requestType,VolleyError error) {
                Log.d(TAG, "Volley requester " + requestType);
                Log.d(TAG, "Volley JSON post" + "That didn't work!");
            }
        };
    }
公共类寄存器扩展AppCompative活动{
EditText用户名TXT;
编辑文本密码;
EditText emailTxt;
请求队列;
布尔formValid=false;
截击发球;
IResult mResultCallback;
静态最终字符串标记=“request12”;
最终字符串URL=”http://10.0.2.2:3000/register";
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//隐藏状态栏
requestWindowFeature(窗口。功能\u无\u标题);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,WindowManager.LayoutParams.FLAG_全屏);
setContentView(R.layout.activity\u寄存器);
initVolleyCallback();
//凌空抽射使排队变得不专业
queue=Volley.newRequestQueue(this);
//使表单字段非专业化
usernameTxt=(EditText)findViewById(R.id.username);
passwordTxt=(EditText)findViewById(R.id.password);
emailTxt=(EditText)findViewById(R.id.email);
//为开发阶段设置文本
usernameTxt.setText(“afcosta5”);
passwordTxt.setText(“moitarioavE10”);
emailTxt.setText(“filipecosta_10@hotmail.com");
}
公共无效登记簿(视图){
set属性(“http.keepAlive”、“false”);
//获取表单数据
最终字符串username=usernameTxt.getText().toString();
字符串密码=passwordTxt.getText().toString();
字符串email=emailTxt.getText().toString();
Log.d(“email”,String.valueOf(isValidEmail(email));
如果(!isValidEmail(电子邮件)){
emailTxt.setError(“无效电子邮件”);
}
//使用配对键值对映射进行初始化
final Map params=new HashMap();
//将表单字段添加到映射
参数put(“用户名”,用户名);
参数put(“电子邮件”,电子邮件);
参数put(“密码”,密码);
JSONObject sendObj=新的JSONObject(参数);
mVolleyService=新的截击服务(mResultCallback,this);
postDataVolley(URL,sendObj);
void initVolleyCallback(){
mResultCallback=new-IResult(){
@凌驾
public void notifySuccess(字符串请求类型,JSONObject响应){
日志d(“GJ”,“成功”);
}
@凌驾
public void notifyError(字符串请求类型,截击错误){
Log.d(标签,“截击请求者”+请求类型);
Log.d(标记为“凌空JSON post”+“这不起作用!”);
}
};
}
我真的不知道问题出在哪里,需要一些帮助从“onCreate()”中删除“initVolleyCallback()”方法

public class Register extends AppCompatActivity implements IResult 
然后必须实现IResult的重写方法

@Override
public void notifySuccess(String requestType,JSONObject response) {
    Log.d("GJ","success");
}

@Override
public void notifyError(String requestType,VolleyError error) {
     Log.d(TAG, "Volley requester " + requestType);
     Log.d(TAG, "Volley JSON post" + "That didn't work!");
}