问题描述
下面是相关的日志猫的信息:
11-09 16:45:47.354 5149-5149 / com.example.apex.apex E /缓存器的错误:错误转换结果显示java.lang.NullPointerException:锁== NULL
11-09 16:45:47.354 5149-5149 / com.example.apex.apex E / JSON解析器:错误解析数据org.json.JSONException:输入结束的字符0
11-09 16:45:47.354 5149-5149 / com.example.apex.apex D / AndroidRuntime:关闭虚拟机
11-09 16:45:47.354 5149-5149 / com.example.apex.apex W / dalvikvm:主题ID = 1:螺纹退出与未捕获的异常(组= 0x41bd9ce0)
工艺:com.example.apex.apex,PID:5149
显示java.lang.NullPointerException
在com.example.apex.apex.RegisterActivity $ 1.onClick(RegisterActivity.java:70)
在android.view.View.performClick(View.java:4445)
在android.view.View $ PerformClick.run(View.java:18446)
在android.os.Handler.handleCallback(Handler.java:733)
在android.os.Handler.dispatchMessage(Handler.java:95)
在android.os.Looper.loop(Looper.java:136)
在android.app.ActivityThread.main(ActivityThread.java:5146)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:515)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:732)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
在dalvik.system.NativeStart.main(本机方法)
11-09 16:46:36.686 5149-5149 / com.example.apex.apex I /工艺:发送信号。 PID:5149 SIG:9
RegisterActivity.java:
我是新来的Java和Android的发展,因此,我开始硬编码的数据通过PHP远程服务器进行通信。
进口android.app.Activity;
进口android.os.Build;
进口android.os.Bundle;
进口android.os.StrictMode;
进口android.view.Menu;
进口android.view.MenuItem;
进口android.view.View;
进口android.widget.Button;
进口android.widget.TextView;
进口org.json.JSONException;
进口org.json.JSONObject;
进口java.sql.Date;
进口java.text.ParseException;
进口java.text.SimpleDateFormat的;
公共类RegisterActivity延伸活动{
私有静态字符串KEY_SUCCESS =成功;
私有静态字符串KEY_ERROR =错误;
私有静态字符串KEY_ERROR_MSG =ERROR_MSG;
按钮btnRegister;
TextView的registerErrorMsg;
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_register);
如果(Build.VERSION.SDK_INT→8)
{
。StrictMode.ThreadPolicy政策=新StrictMode.ThreadPolicy.Builder()permitAll()建();
StrictMode.setThreadPolicy(政策);
}
//导入所有资产
btnRegister =(按钮)findViewById(R.id.btnRegister);
btnRegister.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
//输入
字符串FNAME =约翰;
字符串LNAME =史密斯;
字符串email [email protected];
字符串password =123345;
字符串位置=斯莱戈;
字符串DOB =1993年7月10日;
SimpleDateFormat的SDF =新的SimpleDateFormat(DD-MM-YYYY);
java.util.Date日期= NULL;
尝试 {
日期= sdf.parse(DOB);
}赶上(ParseException的E){
e.printStackTrace();
}
java.sql.Date sqlDob =新的日期(date.getTime());
字符串性别=男;
INT高= 128;
双体重= 78.5;
CyclistFunctions cyclistFunction =新CyclistFunctions();
JSONObject的JSON = cyclistFunction.registerCyclist(FNAME,LNAME,电子邮件,密码,
位置,sqlDob,性别,身高,体重);
//检查登记响应
尝试 {
如果(json.getString(KEY_SUCCESS)!= NULL){
registerErrorMsg.setText();
字符串解析度= json.getString(KEY_SUCCESS);
如果(的Integer.parseInt(RES)== 1){
//用户注册成功
在SQLite的DB //存储用户信息
数据库处理器DB =新的数据库处理器(getApplicationContext());
JSONObject的json_user = json.getJSONObject(用户);
在数据库//清除所有previous数据
完();
} 其他 {
registerErrorMsg.setText(登记发生错误:/);
}
}
}赶上(JSONException E){
e.printStackTrace();
}
}
});
}
@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
//充气菜单;这增加了项目操作栏,如果它是present。
。getMenuInflater()膨胀(R.menu.register,菜单);
返回true;
}
@覆盖
公共布尔onOptionsItemSelected(菜单项项){
//处理动作栏项目点击这里。将操作栏
//自动在主/向上按钮操作的点击,只要
//你在AndroidManifest.xml中指定一个父活动。
INT的id = item.getItemId();
如果(ID == R.id.action_settings){
返回true;
}
返回super.onOptionsItemSelected(项目);
}
}
activity_register.xml
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:以下属性来=@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_margin
机器人:paddingTop =@扪/ activity_vertical_margin
机器人:paddingBottom会=@扪/ activity_vertical_margin
工具:上下文=com.example.apex.apex.RegisterActivity>
<按钮
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / btnRegister
机器人:文本=!点击/>
<的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ ID / btnRegister
机器人:layout_marginTop =50dp/>
JSONParser.java
包com.example.apex.apex;
进口android.util.Log;
进口org.apache.http.HttpEntity;
进口org.apache.http.Htt presponse;
进口org.apache.http.NameValuePair;
进口org.apache.http.client.ClientProtocolException;
进口org.apache.http.client.entity.UrlEn codedFormEntity;
进口org.apache.http.client.methods.HttpPost;
进口org.apache.http.impl.client.DefaultHttpClient;
进口org.apache.http.protocol.HTTP;
进口org.json.JSONException;
进口org.json.JSONObject;
进口java.io.BufferedReader中;
进口java.io.IOException异常;
进口的java.io.InputStream;
进口java.io.InputStreamReader中;
进口java.io.UnsupportedEncodingException;
进口的java.util.List;
公共类JSONParser {
静态的InputStream是= NULL;
静态的JSONObject jObj = NULL;
静态JSON字符串=;
//构造
公共JSONParser(){
}
公众的JSONObject getJSONFromUrl(字符串URL,列表和LT;的NameValuePair> PARAMS){
//使HTTP请求
尝试 {
//创建一个从参数一个新的HTTP客户端和连接管理器
DefaultHttpClient的HttpClient =新DefaultHttpClient();
HttpPost httpPost =新HttpPost(URL);
httpPost.setEntity(新UrlEn codedFormEntity(PARAMS));
HTT presponse HTT presponse = httpClient.execute(httpPost);
HttpEntity httpEntity = HTT presponse.getEntity();
是= httpEntity.getContent();
}赶上(UnsupportedEncodingException E){
e.printStackTrace();
}赶上(ClientProtocolException E){
e.printStackTrace();
}赶上(IOException异常E){
e.printStackTrace();
}
尝试 {
//缓冲区投入是
的BufferedReader读卡器=新的BufferedReader(新的InputStreamReader
(是,HTTP.UTF_8),8);
StringBuilder的SB =新的StringBuilder();
串线= NULL;
而((行= reader.readLine())!= NULL){
sb.append(行+\ N);
}
is.close();
JSON = sb.toString();
Log.e(JSON,JSON);
}赶上(例外五){
Log.e(缓冲区错误,转换的结果错误+ e.toString());
}
//尝试解析字符串JSON对象
尝试 {
jObj =新的JSONObject(JSON);
}赶上(JSONException E){
Log.e(JSON解析器,错误分析数据+ e.toString());
}
//返回JSON字符串
返回jObj;
}
}
CyclistFunctions.java
包com.example.apex.apex;
进口org.apache.http.NameValuePair;
进口org.apache.http.message.BasicNameValuePair;
进口org.json.JSONObject;
进口java.sql.Date;
进口的java.util.ArrayList;
进口的java.util.List;
公共类CyclistFunctions {
私人JSONParser jsonParser;
私有静态最后弦乐REGISTERURL =http://127.0.0.1/apexdb/include/db_functions.php/;
私有静态字符串register_tag =注册;
//构造
公共CyclistFunctions(){
jsonParser =新JSONParser();
}
/ **
*化妆注册请求
* /
公众的JSONObject registerCyclist(FIRST_NAME字符串,字符串姓氏,字符串EMAIL_ADDRESS,
密码字符串,字符串位置,日期birth_date,字符串性别,
INT height_cm,双weight_kg){
//建立参数
名单<的NameValuePair> PARAMS =新的ArrayList<的NameValuePair>();
params.add(新BasicNameValuePair(标签,register_tag));
params.add(新BasicNameValuePair(FIRST_NAME,FIRST_NAME));
params.add(新BasicNameValuePair(姓氏,姓氏));
params.add(新BasicNameValuePair(EMAIL_ADDRESS,EMAIL_ADDRESS));
params.add(新BasicNameValuePair(密码,密码));
params.add(新BasicNameValuePair(位置,位置));
params.add(新BasicNameValuePair(birth_date,将String.valueOf(birth_date)));
params.add(新BasicNameValuePair(性别,性别));
params.add(新BasicNameValuePair(height_cm,将String.valueOf(height_cm)));
params.add(新BasicNameValuePair(weight_kg,将String.valueOf(weight_kg)));
//获取JSON对象
JSONObject的JSON = jsonParser.getJSONFromUrl(REGISTERURL,则params);
//返回JSON
返回JSON;
}
}
db_functions.php
< PHP
类DB_Functions {
私人$分贝;
//构造
功能__construct(){
require_once'db_connect.php;
//连接到数据库
$这个 - > DB =新db_connect();
$这个 - > DB->连接();
}
//析构函数
功能__destruct(){
}
/ **
存储新骑单车
返回用户的详细信息
** /
公共职能storeCyclist($ FIRST_NAME,$姓氏,$ EMAIL_ADDRESS,
$密码,$ birth_date,$性别,$ height_cm,$ weight_kg){
$哈希= $这个 - > hashSSHA($密码);
$ encrypted_password = $哈希[加密]; // 密码
$盐= $哈希[盐]; // 盐
$结果= mysqli_query(INSERT INTO骑车人(名字,姓氏,EMAIL_ADDRESS,
encrypted_password,盐,birth_date,性别,height_cm,weight_kg,DATE_CREATED)
VALUES('$如first_name,$姓氏,$ EMAIL_ADDRESS','$ encrypted_password','$盐,$ birth_date',
'$性别,$ height_cm','$ weight_kg',正()));
如果($结果){
//成功插入骑单车到数据库
$响应[成功] = 1;
$响应[信息] =骑单车成功创建;
//回声JSON响应
回声json_en code($响应);
} 其他 {
//插入失败
$响应[成功] = 1;
$响应[信息] =!Woops,出事了 - 无法创建新的骑自行车者:(;
}
}
公共职能userExists($ EMAIL_ADDRESS){
$结果= mysqli_query(从骑车者选择EMAIL_ADDRESS WHERE EMAIL_ADDRESS ='$ EMAIL_ADDRESS');
$ no_of_rows = mysqli_num_rows($结果);
如果($ no_of_rows大于0){
//用户存在
返回true;
} 其他 {
//用户存在
返回false;
}
}
/ **
加密密码
@参数密码
回报盐
** /
公共职能hashSSHA($密码){
$盐= SHA1(RAND());
$盐= SUBSTR($盐,0,10);
$加密= base64_en code(SHA1($密码$盐,真)$盐);
$哈希=阵列(盐=> $盐,加密=> $加密);
返回$散列;
}
/ **
解密密码
@params盐,密码
返回哈希字符串
** /
公共职能checkSSHA($盐,$密码){
$哈希= base64_en code(SHA1($密码$盐,真)$盐);
返回$散列;
}
}
?>
DB_Connect.php
< PHP
类DB_Connect {
//构造
功能__construct(){
}
//析构函数
功能__destruct(){
// $这个 - >关闭();
}
//连接到数据库
公共功能进行连接(){
require_once'config.php文件;
//连接到的mysqli
$ CON =新mysqli_connect($ DB_HOST,$ DB_USER,$ DB_PASSWORD,$ DB_NAME);
//检查连接
如果(mysqli_connect_errno())
{
回声无法连接到MySQL:.mysqli_connect_errno();
}
//返回数据库处理程序
返回$ CON;
}
公共职能的close(){
//关闭连接
mysqli_close();
}
}
?>
您必须发表您的JSON模式和cyclistic功能,以确定确切的问题。
这行产生错误
的JSONObject JSON = cyclistFunction.registerCyclist(FNAME,LNAME,电子邮件,密码,
位置,sqlDob,性别,身高,体重);
它是这样
字符串result_json = cyclistFunction.registerCyclist(FNAME,LNAME,电子邮件,密码,位置,sqlDob,性别,身高,体重);
如果(result_json!= NULL){
尝试 {
JSONObject的jsonObj =新的JSONObject(result_json);
如果(jsonObj!= NULL){
字符串解析度= json.getString(KEY_SUCCESS);
}
}赶上(JSONException E){
e.printStackTrace();
}
} 其他 {
Log.e(JSON数据,未从服务器接收到任何数据!);
}
Here is the relevant log-cat information:
11-09 16:45:47.354 5149-5149/com.example.apex.apex E/Buffer Error﹕ Error converting result java.lang.NullPointerException: lock == null
11-09 16:45:47.354 5149-5149/com.example.apex.apex E/JSON Parser﹕ Error parsing data org.json.JSONException: End of input at character 0 of
11-09 16:45:47.354 5149-5149/com.example.apex.apex D/AndroidRuntime﹕ Shutting down VM
11-09 16:45:47.354 5149-5149/com.example.apex.apex W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41bd9ce0)
Process: com.example.apex.apex, PID: 5149
java.lang.NullPointerException
at com.example.apex.apex.RegisterActivity$1.onClick(RegisterActivity.java:70)
at android.view.View.performClick(View.java:4445)
at android.view.View$PerformClick.run(View.java:18446)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
at dalvik.system.NativeStart.main(Native Method)
11-09 16:46:36.686 5149-5149/com.example.apex.apex I/Process﹕ Sending signal. PID: 5149 SIG: 9
RegisterActivity.java:
I am new to Java and Android development, therefore I am initially hard-coding data to communicate with a remote server through PHP.
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class RegisterActivity extends Activity {
private static String KEY_SUCCESS = "success";
private static String KEY_ERROR = "error";
private static String KEY_ERROR_MSG = "error_msg";
Button btnRegister;
TextView registerErrorMsg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
if(Build.VERSION.SDK_INT > 8)
{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
// import all assets
btnRegister = (Button) findViewById(R.id.btnRegister);
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// inputs
String fName = "John";
String lName = "Smith";
String email = "[email protected]";
String password = "123345";
String location = "Sligo";
String dob = "07-10-1993";
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
java.util.Date date = null;
try {
date = sdf.parse(dob);
} catch (ParseException e) {
e.printStackTrace();
}
java.sql.Date sqlDob = new Date(date.getTime());
String gender = "Male";
int height = 128;
double weight = 78.5;
CyclistFunctions cyclistFunction = new CyclistFunctions();
JSONObject json = cyclistFunction.registerCyclist(fName, lName, email, password,
location, sqlDob, gender, height, weight);
// check for register response
try {
if (json.getString(KEY_SUCCESS) != null) {
registerErrorMsg.setText("");
String res = json.getString(KEY_SUCCESS);
if(Integer.parseInt(res) == 1) {
// user successfully registered
// store user details in SQLite DB
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
JSONObject json_user = json.getJSONObject("user");
// clear all previous data in database
finish();
} else {
registerErrorMsg.setText("Error in registration occurred! :/");
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.register, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_register.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.apex.apex.RegisterActivity">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/btnRegister"
android:text="Click!"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btnRegister"
android:layout_marginTop="50dp"/>
JSONParser.java
package com.example.apex.apex;
import android.util.Log;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
// constructor
public JSONParser() {
}
public JSONObject getJSONFromUrl(String url, List<NameValuePair> params) {
// make HTTP request
try {
// creates a new HTTP client from parameters and a connection manager
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
// buffer input from is
BufferedReader reader = new BufferedReader(new InputStreamReader
(is, HTTP.UTF_8), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
Log.e("JSON", json);
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try to parse the string to JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
}
CyclistFunctions.java
package com.example.apex.apex;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
public class CyclistFunctions {
private JSONParser jsonParser;
private static final String registerURL = "http://127.0.0.1/apexdb/include/db_functions.php/";
private static String register_tag = "register";
// constructor
public CyclistFunctions() {
jsonParser = new JSONParser();
}
/**
* make register request
*/
public JSONObject registerCyclist(String first_name, String last_name, String email_address,
String password, String location, Date birth_date, String gender,
int height_cm, double weight_kg) {
// build parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", register_tag));
params.add(new BasicNameValuePair("first_name", first_name));
params.add(new BasicNameValuePair("last_name", last_name));
params.add(new BasicNameValuePair("email_address", email_address));
params.add(new BasicNameValuePair("password", password));
params.add(new BasicNameValuePair("location", location));
params.add(new BasicNameValuePair("birth_date", String.valueOf(birth_date)));
params.add(new BasicNameValuePair("gender", gender));
params.add(new BasicNameValuePair("height_cm", String.valueOf(height_cm)));
params.add(new BasicNameValuePair("weight_kg", String.valueOf(weight_kg)));
// fetch JSON object
JSONObject json = jsonParser.getJSONFromUrl(registerURL, params);
// return json
return json;
}
}
db_functions.php
<?php
class DB_Functions {
private $db;
// constructor
function __construct() {
require_once 'db_connect.php';
// connecting to database
$this->db = new db_connect();
$this->db->connect();
}
// destructor
function __destruct() {
}
/**
Storing new cyclist
return user details
**/
public function storeCyclist($first_name, $last_name, $email_address,
$password, $birth_date, $gender, $height_cm, $weight_kg) {
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"]; // password
$salt = $hash["salt"]; // salt
$result = mysqli_query("INSERT INTO cyclist (first_name, last_name, email_address,
encrypted_password, salt, birth_date, gender, height_cm, weight_kg, date_created)
VALUES ('$first_name', '$last_name', '$email_address', '$encrypted_password', '$salt', '$birth_date',
'$gender', '$height_cm', '$weight_kg', NOW())");
if($result) {
// successfully inserted cyclist into database
$response["success"] = 1;
$response["message"] = "Cyclist succesfully created";
// echo JSON response
echo json_encode($response);
} else {
// insert fail
$response["success"] = 1;
$response["message"] = "Woops, something went wrong - failed to create new cyclist! :(";
}
}
public function userExists($email_address) {
$result = mysqli_query("SELECT email_address from cyclist WHERE email_address = '$email_address'");
$no_of_rows = mysqli_num_rows($result);
if($no_of_rows > 0) {
// user exists
return true;
} else {
// user exists
return false;
}
}
/**
encrypt password
@param password
returns salt
**/
public function hashSSHA($password) {
$salt = sha1(rand());
$salt = substr($salt, 0, 10);
$encrypted = base64_encode(sha1($password . $salt, true) . $salt);
$hash = array("salt" => $salt, "encrypted" => $encrypted);
return $hash;
}
/**
decrypting password
@params salt, password
returns hash string
**/
public function checkSSHA($salt, $password) {
$hash = base64_encode(sha1($password . $salt, true) . $salt);
return $hash;
}
}
?>
DB_Connect.php
<?php
class DB_Connect {
// constructor
function __construct() {
}
// destructor
function __destruct() {
// $this->close();
}
// connecting to database
public function connect() {
require_once 'config.php';
// connecting to mysqli
$con = new mysqli_connect($db_host, $db_user, $db_password, $db_name);
// check connection
if(mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " .mysqli_connect_errno();
}
// return db handler
return $con;
}
public function close() {
// close connection
mysqli_close();
}
}
?>
You must post your json model and cyclistic functions in order to identify exact issues.
This line is creating errors
JSONObject json = cyclistFunction.registerCyclist(fName, lName, email, password,
location, sqlDob, gender, height, weight);
It has to be like this
String result_json = cyclistFunction.registerCyclist(fName, lName, email, password,location, sqlDob, gender, height, weight);
if (result_json != null) {
try {
JSONObject jsonObj = new JSONObject(result_json );
if (jsonObj != null) {
String res = json.getString(KEY_SUCCESS);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("JSON Data", "Didn't receive any data from server!");
}
这篇关于错误转换结果显示java.lang.NullPointerException:锁== NULL和错误分析数据org.json.JSONException:输入的字符0结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!