简体   繁体   English

java.lang.RuntimeException:执行doInBackground()URI时发生错误

[英]java.lang.RuntimeException: An error occured while executing doInBackground() URI

i am new to android programming i am trying to write code for a app i am trying to use URI but it keeps giving the following error looking for help 我是android编程的新手,我正在尝试为应用程序编写代码,我正在尝试使用URI,但它不断出现以下错误以寻求帮助

java file Java文件

package com.example.ayushspc.digilocker;

import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Text;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

public class GetRegDetails extends AppCompatActivity {
    Register register = new Register();
    EditText ET_MOBILE, ET_EMAIL;
    String json_string;
    JSONArray jsonArray;
    JSONObject jsonObject;
    String name, branch, email, mobile, enroll, OTP;
    OTPGenerator otpGenerator;
    Sendsms sendsms;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        otpGenerator = new OTPGenerator();
        sendsms = new Sendsms();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_get_reg_details);

        enroll = register.enroll;
        json_string = getIntent().getExtras().getString("jsonresult");

        try {
            jsonObject = new JSONObject(json_string);
            jsonArray = jsonObject.getJSONArray("server_response");
            int count = 0;
            while (count < jsonArray.length()) {
                JSONObject JO = jsonArray.getJSONObject(count);
                name = JO.getString("name");
                branch = JO.getString("branch");
                count++;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        TextView tv_name = (TextView) findViewById(R.id.ver_name);
        TextView tv_branch = (TextView) findViewById(R.id.ver_branch);
        tv_name.setText(name);
        tv_name.setVisibility(View.VISIBLE);
        tv_branch.setText(branch);
        tv_branch.setVisibility(View.VISIBLE);

    }

    public void verifyDetails(View view) {
        ET_MOBILE = (EditText) findViewById(R.id.ver_mobile);
        ET_EMAIL = (EditText) findViewById(R.id.ver_email);
        mobile = ET_MOBILE.getText().toString();
        email = ET_EMAIL.getText().toString();
        OTP = otpGenerator.generator();
        String number = mobile.toString();
        // sendsms.message(number, OTP);//add enrollment number to message;pass mesage as an argument
        Toast.makeText(getApplicationContext(), mobile + " " + OTP, Toast.LENGTH_SHORT).show();
        new BackgroundTask().execute(enroll, mobile, email, OTP);
        Toast.makeText(getApplicationContext(), OTP, Toast.LENGTH_LONG).show();

    }

    class BackgroundTask extends AsyncTask<String, Void, String> {
        String otp_url = "http://www.digiloc.esy.es/otp_verification.php";

        @Override
        protected String doInBackground(String... params) {
            String enrollment, mobile, email, otp;
            enrollment = params[0];
            mobile = params[1];
            email = params[2];
            otp = params[3];

            try {
                URL url = new URL(otp_url);
                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                httpURLConnection.setRequestMethod("POST");
                httpURLConnection.setDoOutput(true);
                OutputStream outputStream = httpURLConnection.getOutputStream();
                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
                String data = URLEncoder.encode("enroll", "UTF-8") + "=" + URLEncoder.encode(enrollment, "UTF-8") + "&" +
                        URLEncoder.encode("mobile", "UTF-8") + "=" + URLEncoder.encode(mobile, "UTF-8") + "&" +
                        URLEncoder.encode("email", "UTF-8") + "=" + URLEncoder.encode(email, "UTF-8") + "&" +
                        URLEncoder.encode("otp", "UTF-8") + "=" + URLEncoder.encode(otp, "UTF-8");
                bufferedWriter.write(data);
                bufferedWriter.flush();
                bufferedWriter.close();
                outputStream.close();

            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            return null;
        }
    }
}

Log file 日志文件

02-06 22:12:05.140  11850-12852/com.example.ayushspc.digilocker E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #4
    java.lang.RuntimeException: An error occured while executing doInBackground()
            at android.os.AsyncTask$3.done(AsyncTask.java:299)
            at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
            at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
            at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
            at java.util.concurrent.FutureTask.run(FutureTask.java:137)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
            at java.lang.Thread.run(Thread.java:864)
     Caused by: java.lang.NullPointerException
            at libcore.net.UriCodec.encode(UriCodec.java:132)
            at java.net.URLEncoder.encode(URLEncoder.java:57)
            at com.example.ayushspc.digilocker.GetRegDetails$BackgroundTask.doInBackground(GetRegDetails.java:102)
            at com.example.ayushspc.digilocker.GetRegDetails$BackgroundTask.doInBackground(GetRegDetails.java:84)
            at android.os.AsyncTask$2.call(AsyncTask.java:287)
            at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
            at java.util.concurrent.FutureTask.run(FutureTask.java:137)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
            at java.lang.Thread.run(Thread.java:864)
02-06 22:12:05.400  11850-11850/com.example.ayushspc.digilocker E/copybit﹕ Error opening frame buffer errno=13 (Permission denied)

can someone possibly point out the cause of error and also a way to solve it 有人可以指出错误的原因以及解决错误的方法吗

enroll = register.enroll;

register.enroll returns null. register.enroll返回null。 Show Register class or try to find a problem by yourself. 显示Register课程或尝试自己发现问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.RuntimeException:执行doInBackground()时发生错误 - java.lang.RuntimeException:An error occured while executing doInBackground() 致命异常:AsyncTask#1 java.lang.RuntimeException:在执行doInBackground()并将图像发送到服务器时发生错误 - FATAL EXCEPTION: AsyncTask #1 java.lang.RuntimeException: An error occured while executing doInBackground(), while sending an image to the Server 如何解决错误java.lang.RuntimeException:执行doInBackground()时发生错误? - how to solve the error java.lang.RuntimeException: An error occured while executing doInBackground()? 非常基本的android代码发布错误。 java.lang.RuntimeException:执行doInBackground()时发生错误 - Very basic android code posts error. java.lang.RuntimeException: An error occured while executing doInBackground() 致命异常:AsyncTask#1:java.lang.RuntimeException:执行doInBackground()时发生错误 - FATAL EXCEPTION: AsyncTask #1:java.lang.RuntimeException: An error occured while executing doInBackground() java.lang.RuntimeException:在执行doInBackground()致命错误时发生错误:AsyncTask#2 - java.lang.RuntimeException: An error occured while executing doInBackground() FATAL EXCEPTION: AsyncTask #2 E / AndroidRuntime:致命例外:AsyncTask#1 java.lang.RuntimeException:执行doInBackground()时发生错误 - E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 java.lang.RuntimeException: An error occured while executing doInBackground() 如何解决此问题:执行doInBackground()时发生致命异常Asynctask#1 java.lang.RuntimeException错误 - how to solve this : Fatal Exception Asynctask #1 java.lang.RuntimeException error occured while executing doInBackground() java.lang.RuntimeException:执行doInBackground()时发生错误 - java.lang.RuntimeException: An error occurred while executing doInBackground() 致命异常:asynctask#1 java.lang.runtimeException:执行doinbackground时发生错误 - fatal exception : asynctask #1 java.lang.runtimeException: an error occured while excuting doinbackground
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM