本文介绍了错误分析数据org.json.JSONException:值小于; BR java.lang.String类型不能转换成的JSONObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直试图对这些codeS,我想送它会自动生成密码和随机密码,然后在我的数据库列这是encrypted_pa​​ssword更新的电子邮件。

我真的不知道什么是错我的code。我是新来这个Android应用程序也使用了PHP。而且我也看到了一些其他的问题,这是链接到我的,但是,我仍然无法解决这个问题。谁能帮帮我吗?我真的需要这个帮助我的最后一年的项目。

另一件事情也派遣与随机生成的密码的电子邮件后,随机生成的密码不能被更新到我的数据库列。

这是我的错误:

  10月8日至29日:44:10.976:E / JSON解析器(1594):错误解析数据org.json.JSONException:值小于; BR java.lang.String类型不了被转换成的JSONObject
10月8号至29号:44:10.987:W / dalvikvm(1594):主题ID = 10:线程退出与未捕获的异常(组= 0x40014760)
10月8号至29号:44:11.006:E / AndroidRuntime(1594):致命异常:AsyncTask的#1
10月8号至29号:44:11.006:E / AndroidRuntime(1594):java.lang.RuntimeException的:一个错误而执行doInBackground发生()
10月8号至29号:44:11.006:E / AndroidRuntime(1594):在android.os.AsyncTask $ 3.done(AsyncTask.java:266)
10月8号至29号:44:11.006:E / AndroidRuntime(1594):在java.util.concurrent.FutureTask中$ Sync.innerSetException(FutureTask.java:273)
10月8号至29号:44:11.006:E / AndroidRuntime(1594):在java.util.concurrent.FutureTask.setException(FutureTask.java:124)
10月8号至29号:44:11.006:E / AndroidRuntime(1594):在java.util.concurrent.FutureTask中$ Sync.innerRun(FutureTask.java:307)
10月8号至29号:44:11.006:E / AndroidRuntime(1594):在java.util.concurrent.FutureTask.run(FutureTask.java:137)
10月8号至29号:44:11.006:E / AndroidRuntime(1594):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
10月8号至29号:44:11.006:E / AndroidRuntime(1594):在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:574)
10月8号至29号:44:11.006:E / AndroidRuntime(1594):在java.lang.Thread.run(Thread.java:1020)
10月8号至29号:44:11.006:E / AndroidRuntime(1594):由:显示java.lang.NullPointerException
10月8号至29号:44:11.006:E / AndroidRuntime(1594):在com.pivestigator.login.ForgetPasswordActivity$SendEmail.doInBackground(ForgetPasswordActivity.java:93)
10月8号至29号:44:11.006:E / AndroidRuntime(1594):在com.pivestigator.login.ForgetPasswordActivity$SendEmail.doInBackground(ForgetPasswordActivity.java:1)
10月8号至29号:44:11.006:E / AndroidRuntime(1594):在android.os.AsyncTask $ 2.call(AsyncTask.java:252)
10月8号至29号:44:11.006:E / AndroidRuntime(1594):在java.util.concurrent.FutureTask中$ Sync.innerRun(FutureTask.java:305)
 

我的Andr​​oid code:

 公共类ForgetPasswordActivity延伸活动{

的EditText textforgetEmail;
TextView的email_error;

 //进度对话框
私人ProgressDialog pDialog;

 私有静态字符串url_email =...;

// JSON节点名称
        私有静态最后弦乐TAG_SUCCESS =成功;

    JSONParser jsonParser =新JSONParser();

@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.forget_password);

    按钮buttonSubmit =(按钮)findViewById(R.id.buttonSubmit);
    textforgetEmail =(EditText上)findViewById(R.id.forgetEmail);
    email_error =(TextView中)findViewById(R.id.email_error);

    //链接登录屏幕
    buttonSubmit.setOnClickListener(新View.OnClickListener(){

            公共无效的onClick(视图查看){
                //创建在后台线程的新产品
                新SendEmail()执行()。
            }
    });

}

类SendEmail扩展的AsyncTask<字符串,字符串,字符串> {
    @覆盖
    在preExecute保护无效(){
        super.on preExecute();
        pDialog =新ProgressDialog(ForgetPasswordActivity.this);
       // pDialog.setMessage(发送电子邮件..);
        pDialog.setIndeterminate(假);
        pDialog.setCancelable(真正的);
       // pDialog.show();
    }

    保护字符串doInBackground(字符串参数... args){
        runOnUiThread(新的Runnable(){
            公共无效的run(){
                //发送电子邮件方法HERE
                。字符串sendemail = textforgetEmail.getText()的toString();

                //大厦参数
                名单<的NameValuePair> PARAMS =新的ArrayList<的NameValuePair>();
                params.add(新BasicNameValuePair(电子邮件,sendemail));

                //获取JSON对象
                //注意forgotPassword URL接受POST方法
                JSONObject的JSON = jsonParser.makeHtt prequest(
                        url_email,POST,则params);

                //检查日志猫响应
                 //Log.d("Sending电子邮件回复,json.toString());

                //检查成功标签
                尝试 {
                    INT成功= json.getInt(TAG_SUCCESS);

                    如果(成功== 1){
                        //成功电子邮件发送
                        意向意图=新的意图(getApplicationContext()
                                ForgetPasswordConfirmActivity.class);
                        startActivity(意向);
                        完();
                    } 其他 {
                        //无法发送电子邮件
                    }
                }赶上(JSONException E){
                    e.printStackTrace();
                }
            }
        });
        返回null;
    }

    保护无效onPostExecute(字符串file_url){
        //驳回一旦完成对话
        pDialog.dismiss();
    }
}

 }
 

和我的PHP文件:

 < PHP

$响应=阵列();

$随机= str_rand();

 功能str_rand($长度= 8,$种子='alphanum')
{
//可能的种子
$播种['阿尔法'] ='abcdefghijklmnopqrstuvwqyz';
$播种['数字'] ='0123456789';
$播种['alphanum'] ='abcdefghijklmnopqrstuvwqyz0123456789';
$播种['hexidec'] ='0123456789ABCDEF';

//选择种子
如果(使用isset($种子队[$种子]))
{
    $种子= $种子队[$种子]
}

//种子生成器
列表($微秒,$秒)=爆炸('',microtime中());
$种子=(浮动)$秒+((浮动)$微秒* 100000);
mt_srand($种子);

// 生成
$海峡='';
$ seeds_count =的strlen($种子);

为($ i = 0; $长度GT; $ I; $ I ++)
{
    。$海峡= $种子{mt_rand(0,$ seeds_count  -  1)};
}

返回$海峡;
}

//检查所需的字段
如果(使用isset($ _ POST [电子邮件])){

$电子邮件= $ _ POST [电子邮件];


$到= $电子邮件;
$主题='这是一封电子邮件。;
。$身体='你好',\ñ\ N'这是您的新密码:$随机'测试';。
$标题=发件人:[email protected];

如果(电子邮件($到,$主题,$机构,$头)){
//其中包括DB连接类
require_once __DIR__。 /DB_Connect.php;

//连接到数据库
$ DB =新DB_CONNECT();

//检查是否行插入或不
如果($结果){
    //成功插入到数据库
    $响应[成功] = 1;
    $响应[信息] =邮件发送成功。

    //呼应JSON响应
    回声json_en code($响应);
}

}
其他 {
//必填字段缺失
$响应[成功] = 0;
$响应[信息] =必填字段(S)丢失;

//呼应JSON响应
回声json_en code($响应);
}
 }
?>
 

解决方案

随着错误消息说:

  [..剪断..] json.JSONException:值小于; BR java.lang.String类型不能转换成的JSONObject
                                     ^ ^ ^
 

在JSON字符串你试图解析是无效的 - 看起来像它得到了一些原始的HTML,这意味着它要么产生严重或PHP被插入错误/警告和销毁字符串

Have been trying on these codes and I want to send a email which will auto generate the password and the random password will then update in my database column which is the encrypted_password.

I really dont know whats wrong with my code. I am new to this android application and also using the php. And i did see some other questions that are link to mine, however, I still cant solve it. Can anyone please help me? I really need help on this for my final year project.

Another thing is also after sending the email with the random generated password, the random generated password cannot be updated into my database column.

This is my error:

08-29 10:44:10.976: E/JSON Parser(1594): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
08-29 10:44:10.987: W/dalvikvm(1594): threadid=10: thread exiting with uncaught exception (group=0x40014760)
08-29 10:44:11.006: E/AndroidRuntime(1594): FATAL EXCEPTION: AsyncTask #1
08-29 10:44:11.006: E/AndroidRuntime(1594): java.lang.RuntimeException: An error occured while executing doInBackground()
08-29 10:44:11.006: E/AndroidRuntime(1594):     at android.os.AsyncTask$3.done(AsyncTask.java:266)
08-29 10:44:11.006: E/AndroidRuntime(1594):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-29 10:44:11.006: E/AndroidRuntime(1594):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-29 10:44:11.006: E/AndroidRuntime(1594):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
08-29 10:44:11.006: E/AndroidRuntime(1594):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-29 10:44:11.006: E/AndroidRuntime(1594):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
08-29 10:44:11.006: E/AndroidRuntime(1594):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
08-29 10:44:11.006: E/AndroidRuntime(1594):     at java.lang.Thread.run(Thread.java:1020)
08-29 10:44:11.006: E/AndroidRuntime(1594): Caused by: java.lang.NullPointerException
08-29 10:44:11.006: E/AndroidRuntime(1594):     at com.pivestigator.login.ForgetPasswordActivity$SendEmail.doInBackground(ForgetPasswordActivity.java:93)
08-29 10:44:11.006: E/AndroidRuntime(1594):     at com.pivestigator.login.ForgetPasswordActivity$SendEmail.doInBackground(ForgetPasswordActivity.java:1)
08-29 10:44:11.006: E/AndroidRuntime(1594):     at android.os.AsyncTask$2.call(AsyncTask.java:252)
08-29 10:44:11.006: E/AndroidRuntime(1594):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)

my android code:

 public class ForgetPasswordActivity extends Activity {

EditText textforgetEmail;
TextView email_error;

 // Progress Dialog
private ProgressDialog pDialog;

 private static String url_email = "...";

// JSON Node names
        private static final String TAG_SUCCESS = "success";

    JSONParser jsonParser = new JSONParser();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.forget_password);

    Button buttonSubmit = (Button) findViewById(R.id.buttonSubmit);
    textforgetEmail = (EditText) findViewById(R.id.forgetEmail);
    email_error = (TextView) findViewById(R.id.email_error);

    // Link to Login Screen
    buttonSubmit.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                // creating new product in background thread
                new SendEmail().execute();
            }
    });

}

class SendEmail extends AsyncTask<String, String, String> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(ForgetPasswordActivity.this);
       // pDialog.setMessage("Sending Email..");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
       // pDialog.show();
    }

    protected String doInBackground(String... args) {
        runOnUiThread(new Runnable() {
            public void run() {
                // SENDING EMAIL METHOD HERE
                String sendemail = textforgetEmail.getText().toString();

                // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("email", sendemail));

                // getting JSON Object
                // Note that forgotPassword URL accepts POST method
                JSONObject json = jsonParser.makeHttpRequest(
                        url_email, "POST", params);

                // check log cat for response
                 //Log.d("Sending email Response", json.toString());

                // check for success tag
                try {
                    int success = json.getInt(TAG_SUCCESS);

                    if (success == 1) {
                        // successfully email sent
                        Intent intent = new Intent(getApplicationContext(),
                                ForgetPasswordConfirmActivity.class);
                        startActivity(intent);
                        finish();
                    } else {
                        // failed to send email
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
        return null;
    }

    protected void onPostExecute(String file_url) {
        // dismiss the dialog once done
        pDialog.dismiss();
    }
}

 }

and my php file:

<?php

$response = array();

$random = str_rand();

 function str_rand($length = 8, $seeds = 'alphanum')
{
// Possible seeds
$seedings['alpha'] = 'abcdefghijklmnopqrstuvwqyz';
$seedings['numeric'] = '0123456789';
$seedings['alphanum'] = 'abcdefghijklmnopqrstuvwqyz0123456789';
$seedings['hexidec'] = '0123456789abcdef';

// Choose seed
if (isset($seedings[$seeds]))
{
    $seeds = $seedings[$seeds];
}

// Seed generator
list($usec, $sec) = explode(' ', microtime());
$seed = (float) $sec + ((float) $usec * 100000);
mt_srand($seed);

// Generate
$str = '';
$seeds_count = strlen($seeds);

for ($i = 0; $length > $i; $i++)
{
    $str .= $seeds{mt_rand(0, $seeds_count - 1)};
}

return $str;
}

// check for required fields
if (isset($_POST['email'])) {

$email = $_POST['email'];


$to = $email;
$subject = 'This is an email.';
$body = 'Hi,'."\n\n".'This is your new password: '."$random".'test';
$headers = 'From: [email protected]';

if (mail($to, $subject, $body, $headers)) {
// include db connect class
require_once __DIR__ . '/DB_Connect.php';

// connecting to db
$db = new DB_CONNECT();

// check if row inserted or not
if ($result) {
    // successfully inserted into database
    $response["success"] = 1;
    $response["message"] = "Email successfully sent.";

    // echoing JSON response
    echo json_encode($response);
}

}
else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";

// echoing JSON response
echo json_encode($response);
}
 }
?>
解决方案

As the error message says:

[..snip..] json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
                                     ^^^

The JSON string you're trying to parse is invalid - looks like it's got some raw HTML, which mean it's either badly generated, or PHP is inserting errors/warnings and destroying the string.

这篇关于错误分析数据org.json.JSONException:值小于; BR java.lang.String类型不能转换成的JSONObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:10