应用程序工作正常在仿真器,将数据发送到服务器,但崩溃的设备
问题描述:
以下为引用的代码:应用程序工作正常在仿真器,将数据发送到服务器,但崩溃的设备
的数据进入数据库在本地,我复制它在服务器上,从我的设备访问应用程序,它使用API级别23,这也是我的gradle文件中的目标sdk。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.enter_sugarcane_details_layout);
final EditText etyear = (EditText) findViewById(R.id.textYear);
final EditText etSpecies = (EditText) findViewById(R.id.textSpecies);
final EditText etPlantingDate = (EditText) findViewById(R.id.textPlantingdate);
final EditText etPlantingArea = (EditText) findViewById(R.id.textPlantingarea);
final EditText etProduction = (EditText) findViewById(R.id.textProduction);
final EditText etExpectedAmount = (EditText) findViewById(R.id.textExpectedAmount);
final EditText etSabhasadpart = (EditText) findViewById(R.id.textSabhasadpart);
final EditText etWhere = (EditText) findViewById(R.id.textWhere);
final EditText etDistance = (EditText) findViewById(R.id.textDistance);
final EditText ettransportmode = (EditText) findViewById(R.id.texttransportmode);
final EditText ettransportcost = (EditText) findViewById(R.id.texttransportcost);
final EditText etothersupply = (EditText) findViewById(R.id.textothersupply);
final Button bSave = (Button) findViewById(R.id.btnSavedetails);
bSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String year = etyear.getText().toString();
final String species = etSpecies.getText().toString();
final String pdate = etPlantingDate.getText().toString();
final int parea = Integer.parseInt(etPlantingArea.getText().toString());
final int production = Integer.parseInt(etProduction.getText().toString());
final int expamt = Integer.parseInt(etExpectedAmount.getText().toString());
final String sabhasadpart = etSabhasadpart.getText().toString();
final String where = etWhere.getText().toString();
final int distance = Integer.parseInt(etDistance.getText().toString());
final String transportmode = ettransportmode.getText().toString();
final int transportcost = Integer.parseInt(ettransportcost.getText().toString());
final String othersupply = etothersupply.getText().toString();
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
System.out.println(response);
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
Intent intent = new Intent(EnterSugarcaneDetails.this, UserAreaActivity.class);
EnterSugarcaneDetails.this.startActivity(intent);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(EnterSugarcaneDetails.this);
builder.setMessage("Details were not updated")
.setNegativeButton("Retry", null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
DetailsRequest detailsRequest = new DetailsRequest(year, species, pdate, parea, production, expamt, sabhasadpart, where, distance, transportmode, transportcost, othersupply, responseListener);
RequestQueue queue = Volley.newRequestQueue(EnterSugarcaneDetails.this);
queue.add(detailsRequest);
}
});
}
}
答
menifest
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
也注册
UserAreaActivity.class注册到您的menifest
yourActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.enter_sugarcane_details_layout);
final EditText etyear = (EditText) findViewById(R.id.textYear);
final EditText etSpecies = (EditText) findViewById(R.id.textSpecies);
final EditText etPlantingDate = (EditText) findViewById(R.id.textPlantingdate);
final EditText etPlantingArea = (EditText) findViewById(R.id.textPlantingarea);
final EditText etProduction = (EditText) findViewById(R.id.textProduction);
final EditText etExpectedAmount = (EditText) findViewById(R.id.textExpectedAmount);
final EditText etSabhasadpart = (EditText) findViewById(R.id.textSabhasadpart);
final EditText etWhere = (EditText) findViewById(R.id.textWhere);
final EditText etDistance = (EditText) findViewById(R.id.textDistance);
final EditText ettransportmode = (EditText) findViewById(R.id.texttransportmode);
final EditText ettransportcost = (EditText) findViewById(R.id.texttransportcost);
final EditText etothersupply = (EditText) findViewById(R.id.textothersupply);
final Button bSave = (Button) findViewById(R.id.btnSavedetails);
if(isNetworkConnected)
{
bSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String year = etyear.getText().toString();
final String species = etSpecies.getText().toString();
final String pdate = etPlantingDate.getText().toString();
final int parea = Integer.parseInt(etPlantingArea.getText().toString());
final int production = Integer.parseInt(etProduction.getText().toString());
final int expamt = Integer.parseInt(etExpectedAmount.getText().toString());
final String sabhasadpart = etSabhasadpart.getText().toString();
final String where = etWhere.getText().toString();
final int distance = Integer.parseInt(etDistance.getText().toString());
final String transportmode = ettransportmode.getText().toString();
final int transportcost = Integer.parseInt(ettransportcost.getText().toString());
final String othersupply = etothersupply.getText().toString();
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
System.out.println(response);
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
Intent intent = new Intent(EnterSugarcaneDetails.this, UserAreaActivity.class);
EnterSugarcaneDetails.this.startActivity(intent);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(EnterSugarcaneDetails.this);
builder.setMessage("Details were not updated")
.setNegativeButton("Retry", null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
DetailsRequest detailsRequest = new DetailsRequest(year, species, pdate, parea, production, expamt, sabhasadpart, where, distance, transportmode, transportcost, othersupply, responseListener);
RequestQueue queue = Volley.newRequestQueue(EnterSugarcaneDetails.this);
queue.add(detailsRequest);
}
});}else{
Toast.makeText(getApplicationContext(),"chec your internet connection", Toast.LENGTH_LONG).show();
}
}
private boolean isNetworkConnected() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo() != null;
}
+0
我使用相同的代码注册了应用程序,这是登录到应用程序后的下一个活动。我在清单中添加了上面提到的所有上述内容! –
+0
可以给我发送问题 –
请添加堆栈跟踪以获取崩溃原因。 – Sac
也发布您的崩溃日志!在java.lang.Integer中的 “” : – Abbas
@Pooja认罪张贴在这里您的日志 –