Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.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 Android Json项目应用程序崩溃_Java_Php_Android_Mysql_Json - Fatal编程技术网

Java Android Json项目应用程序崩溃

Java Android Json项目应用程序崩溃,java,php,android,mysql,json,Java,Php,Android,Mysql,Json,我的android开发项目有点麻烦。我创建了一个应用程序,允许用户从MySQL数据库中插入/读取/更新和删除记录。这是使用JSON。应用程序持续崩溃,并出现致命的异常?不太确定是什么,因为创建的页面都没有显示任何错误。我还使用php连接到数据库并查询它。有5个java文件和4个xml布局文件。不知道你是否想让我把它们都放在这里,因为它可能会变得太多,所以现在我会把它们添加到我的dropbox公共文件夹中,如果我需要把所有的页面都放在这里,我会编辑问题 更新: 我设法消除了大多数错误,但它发送了一

我的android开发项目有点麻烦。我创建了一个应用程序,允许用户从MySQL数据库中插入/读取/更新和删除记录。这是使用JSON。应用程序持续崩溃,并出现致命的异常?不太确定是什么,因为创建的页面都没有显示任何错误。我还使用php连接到数据库并查询它。有5个java文件和4个xml布局文件。不知道你是否想让我把它们都放在这里,因为它可能会变得太多,所以现在我会把它们添加到我的dropbox公共文件夹中,如果我需要把所有的页面都放在这里,我会编辑问题

更新:

我设法消除了大多数错误,但它发送了一个错误,表示无法找到onClick方法的显式活动类viewallemploye

Process: com.example.assignment.androidassignment, PID: 2211   android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.assignment.androidassignment/com.example.assignment.androidassignment.ViewAllEmployee}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
at android.app.Activity.startActivityForResult(Activity.java:3424)
at android.app.Activity.startActivityForResult(Activity.java:3385)
at android.app.Activity.startActivity(Activity.java:3627)
at android.app.Activity.startActivity(Activity.java:3595)
at com.example.assignment.androidassignment.MainActivity.onClick(MainActivity.java:93)
MainActivity.java

package com.example.assignment.androidassignment;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.HashMap;

public class MainActivity extends Activity implements View.OnClickListener{

//Defining views
private EditText editTextLatitude;
private EditText editTextLongitude;
private EditText editTextTimeInserted;

private Button buttonAdd;
private Button buttonView;

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

    //Initializing views
    editTextLatitude = (EditText) findViewById(R.id.editTextLat);
    editTextLongitude = (EditText) findViewById(R.id.editTextLon);
    editTextTimeInserted = (EditText) findViewById(R.id.editTextTimeInserted);

    buttonAdd = (Button) findViewById(R.id.buttonAdd);
    buttonView = (Button) findViewById(R.id.buttonView);

    //Setting listeners to button
    buttonAdd.setOnClickListener(this);
    buttonView.setOnClickListener(this);
    }


    //Adding an employee
    private void addEmployee(){

    final String lat = editTextLatitude.getText().toString().trim();
    final String lon = editTextLongitude.getText().toString().trim();
    final String timeInserted = editTextTimeInserted.getText().toString().trim();

    class AddEmployee extends AsyncTask<Void,Void,String>{

        ProgressDialog loading;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            loading = ProgressDialog.show(MainActivity.this,"Adding...","Wait...",false,false);
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            loading.dismiss();
            Toast.makeText(MainActivity.this,s,Toast.LENGTH_LONG).show();
        }

        @Override
        protected String doInBackground(Void... v) {
            HashMap<String,String> params = new HashMap<>();
            params.put(Config.KEY_LAT,lat);
            params.put(Config.KEY_LON,lon);
            params.put(Config.KEY_TIMEINSERTED,timeInserted);

            RequestHandler rh = new RequestHandler();
            String res = rh.sendPostRequest(Config.URL_ADD, params);
            return res;
        }
        }

        AddEmployee ae = new AddEmployee();
        ae.execute();
 }

@Override
public void onClick(View v) {
    if(v == buttonAdd){
        addEmployee();
    }

    if(v == buttonView){
        Intent intent = new Intent(MainActivity.this,ViewAllEmployee.class);
        startActivity(intent);

        startActivity(new Intent(this,com.example.assignment.androidassignment.ViewAllEmployee.class));
    }
    } 
}
package com.example.assignment.androidassignment;
导入android.app.Activity;
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.Toast;
导入java.util.HashMap;
公共类MainActivity扩展活动实现View.OnClickListener{
//定义视图
私人编辑文本编辑纬度;
私有编辑文本编辑经度;
私有EditText editTextTimeInserted;
私人按钮按钮;
私人按钮视图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//初始化视图
editTextLatitude=(EditText)findViewById(R.id.editTextLat);
EditText经度=(EditText)findViewById(R.id.editTextLon);
editTextTimeInserted=(EditText)findViewById(R.id.editTextTimeInserted);
ButtonAd=(按钮)findViewById(R.id.ButtonAd);
buttonView=(按钮)findViewById(R.id.buttonView);
//将侦听器设置为按钮
ButtonAd.setOnClickListener(此);
buttonView.setOnClickListener(此);
}
//添加员工
私人雇员(){
最后一个字符串lat=editTextLatitude.getText().toString().trim();
最后一个字符串lon=editTextLength.getText().toString().trim();
final String timeInserted=editTextTimeInserted.getText().toString().trim();
类AddEmployee扩展异步任务{
对话加载;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
加载=ProgressDialog.show(MainActivity.this,“添加…”,“等待…”,false,false);
}
@凌驾
受保护的void onPostExecute(字符串s){
super.onPostExecute(s);
loading.dispose();
Toast.makeText(MainActivity.this,s,Toast.LENGTH_LONG.show();
}
@凌驾
受保护字符串背景(无效…v){
HashMap params=新的HashMap();
参数put(配置键LAT,LAT);
参数put(配置键LON,LON);
参数put(Config.KEY_TIMEINSERTED,TIMEINSERTED);
RequestHandler rh=新的RequestHandler();
String res=rh.sendPostRequest(Config.URL\u ADD,params);
返回res;
}
}
AddEmployee ae=新的AddEmployee();
ae.execute();
}
@凌驾
公共void onClick(视图v){
如果(v==按钮D){
addEmployee();
}
如果(v==按钮视图){
意向意向=新意向(MainActivity.this,ViewAllEmployee.class);
星触觉(意向);
startActivity(新意图(这个,com.example.assignment.androidassignment.viewalleEmployee.class));
}
} 
}
AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.assignment.androidassignment"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="android.permission.INTERNET" />

<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="21" />

<application
android:allowBackup="true"
android:label="@string/app_name" >
<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Holo.Dialog" >

<intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
</application>

</manifest>

更新:ViewAllEmployee.java

package com.example.assignment.assignment;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView; 
import android.widget.SimpleAdapter;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class ViewAllEmployee extends Activity implements ListView.OnItemClickListener {

private ListView listView;

private String JSON_STRING;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_all_employee);
    listView = (ListView) findViewById(R.id.listView);
    listView.setOnItemClickListener(this);
    getJSON();
}


private void showEmployee() {
    JSONObject jsonObject = null;
    ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String,  String>>();
    try {
        jsonObject = new JSONObject(JSON_STRING);
        JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);

        for (int i = 0; i < result.length(); i++) {
            JSONObject jo = result.getJSONObject(i);
            String UserID = jo.getString(Config.TAG_ID);
            String Lat = jo.getString(Config.TAG_LAT);

            HashMap<String, String> employees = new HashMap<>();
            employees.put(Config.TAG_ID, UserID);
            employees.put(Config.TAG_LAT, Lat);
            list.add(employees);
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }

    ListAdapter adapter = new SimpleAdapter(
            ViewAllEmployee.this, list, R.layout.list_item,
            new String[]{Config.TAG_ID, Config.TAG_LAT},
            new int[]{R.id.id, R.id.name});

    listView.setAdapter(adapter);
}

private void getJSON() {
    class GetJSON extends AsyncTask<Void, Void, String> {

        ProgressDialog loading;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            loading = ProgressDialog.show(ViewAllEmployee.this, "Fetching Data", "Wait...", false, false);
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            loading.dismiss();
            JSON_STRING = s;
            showEmployee();
        }

        @Override
        protected String doInBackground(Void... params) {
            RequestHandler rh = new RequestHandler();
            String s = rh.sendGetRequest(Config.URL_GET_ALL);
            return s;
        }
    }
    GetJSON gj = new GetJSON();
    gj.execute();
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Intent intent = new Intent(this, ViewEmployee.class);
    HashMap<String, String> map = (HashMap)  parent.getItemAtPosition(position);
    String UserID = map.get(Config.TAG_ID).toString();
    intent.putExtra(Config.EMP_ID, UserID);
    startActivity(intent);
 }
 }
package com.example.assignment.assignment;
导入android.app.Activity;
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.ListAdapter;
导入android.widget.ListView;
导入android.widget.simpledapter;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入java.util.ArrayList;
导入java.util.HashMap;
导入java.util.ArrayList;
导入java.util.HashMap;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入android.app.Activity;
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.support.v7.app.AppActivity;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.ListAdapter;
导入android.widget.ListView;
导入android.widget.simpledapter;
公共类ViewAllEmployee扩展活动实现ListView.OnItemClickListener{
私有列表视图列表视图;
私有字符串JSON_字符串;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u view\u all\u employee);
listView=(listView)findViewById(R.id.listView);
setOnItemClickListener(this);
getJSON();
}
私人雇员(){
JSONObject JSONObject=null;
ArrayList=新建ArrayList();
试一试{
jsonObject=新的jsonObject(JSON_字符串);
JSONArray result=jsonObject.getJSONArray(Config.TAG\u JSON\u数组);
for(int i=0;i<application ...>
    <activity
        android:name=".ViewAllEmployee" />
</application>