[Android Studio] saeedarhdari:
hi my app is ood but when i hav not internet and cant load data from my database

my app will be force close

my error is in emulatur

130 - AsyncHttpClient.getDefaultInstance().executeString(post, new AsyncHttpClient.StringCallback() {

and

153- if(!result.equals("")){

in this java activity

package com.smartapp.soton;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.afollestad.materialdialogs.MaterialDialog;
import com.baoyz.widget.PullRefreshLayout;
import com.koushikdutta.async.http.AsyncHttpClient;
import com.koushikdutta.async.http.AsyncHttpPost;
import com.koushikdutta.async.http.AsyncHttpResponse;
import com.koushikdutta.async.http.body.MultipartFormDataBody;
import com.koushikdutta.async.http.socketio.ExceptionCallback;
import com.squareup.picasso.Picasso;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

public class Frag_Banners_All extends Fragment {

// Development by SmartMob (Manager : Mohammad Mokhles)
View v ;
Context context ;
GridView gridView ;
public List<HashMap<String , Object>> hash_all ;
String[] items ;
Ad ad ;

int preLast ;
int page = 0 ;
View row ;
ImageView row_list_img1 ;
TextView row_list_title , row_list_price , row_list_time ;
CardView row_list_card ;

PullRefreshLayout refresh ;

[MENTION=3869344]nullable[/MENTION]
[MENTION=439709]override[/MENTION]
public View onCreateView(LayoutInflater inflater, [MENTION=3869344]nullable[/MENTION] ViewGroup container, [MENTION=3869344]nullable[/MENTION] Bundle savedInstanceState) {
v = inflater.inflate(R.layout.frag_banners_all,container,false);
context = v.getContext();
hash_all = new ArrayList<>();
items = new String[hash_all.size()];
ad = new Ad();
gridView = (GridView)v.findViewById(R.id.grid_all);
gridView.setAdapter(ad);

gridView.setOnScrollListener(new AbsListView.OnScrollListener() {
[MENTION=439709]override[/MENTION]
public void onScrollStateChanged(AbsListView view, int scrollState) {

}

[MENTION=439709]override[/MENTION]
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

if(totalItemCount>=10){
final int lastItem = firstVisibleItem + visibleItemCount ;
if(lastItem == totalItemCount){
if(preLast != lastItem){
preLast = lastItem ;
page = page + 1 ;
try {
get_banners(page);
}catch (Exception e){
e.printStackTrace();
}
}
}
}
}
});
page = 0 ;
preLast = 0 ;
CheckNet();

refresh = (PullRefreshLayout)v.findViewById(R.id.refresh);
refresh.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener() {
[MENTION=439709]override[/MENTION]
public void onRefresh() {
page = 0 ;
preLast = 0 ;
CheckNet();
}
});

return v;
}

private void get_banners(final int pages){

MainActivity.wait.show();
AsyncHttpPost post = new AsyncHttpPost(
"this is my linke i removed"
);

post.setTimeout(5000);

MultipartFormDataBody body = new MultipartFormDataBody();

body.addStringPart("City",MainActivity.sp.getString("City",null));
body.addStringPart("Cate","all");
body.addStringPart("Page", String.valueOf(pages));
post.setBody(body);
try{
AsyncHttpClient.getDefaultInstance().executeString(post, new AsyncHttpClient.StringCallback() {
[MENTION=439709]override[/MENTION]
public void onCompleted(final Exception e, AsyncHttpResponse source, final String result) {
CheckNet();
if(e != null){
MainActivity.activity.runOnUiThread(new Runnable() {
[MENTION=439709]override[/MENTION]
public void run() {
try{

refresh.setRefreshing(false);
}catch (Exception e){
e.printStackTrace();
}
MainActivity.wait.dismiss();
Toast.makeText(MainActivity.activity, "خطا در برقراری اتصال با سرور !", Toast.LENGTH_LONG).show();
e.printStackTrace();

}
});
}

if(!result.equals("")){
MainActivity.activity.runOnUiThread(new Runnable() {
[MENTION=439709]override[/MENTION]
public void run() {

MainActivity.wait.dismiss();
if(page==0){
hash_all.clear();
}
items.clone();
try {
JSONArray jsonArray = new JSONArray(result);
for (int i = 0 ;i<jsonArray.length();i++){
JSONObject object = jsonArray.getJSONObject(i);
HashMap<String , Object> hash_add = new HashMap<String, Object>();

hash_add.put("ID",object.getString("ID"));
hash_add.put("Username",object.getString("Username"));
hash_add.put("Title",object.getString("Title"));
hash_add.put("Descript",object.getString("Descript"));
hash_add.put("Price",object.getString("Price"));
hash_add.put("Tell",object.getString("Tell"));
hash_add.put("Email",object.getString("Email"));
hash_add.put("City",object.getString("City"));
hash_add.put("Cate",object.getString("Cate"));
hash_add.put("Img1",object.getString("Img1"));
hash_add.put("Img2",object.getString("Img2"));
hash_add.put("Img3",object.getString("Img3"));
hash_add.put("Date",object.getString("Date"));

hash_all.add(hash_add);
items = new String[hash_all.size()];
}
ad.notifyDataSetChanged();
refresh.setRefreshing(false);
}catch (Exception e){
e.printStackTrace();
}
}
});
}

}
});

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

}

public class Ad extends ArrayAdapter<String>{

private LayoutInflater inflater = null ;

public Ad(){
super(context,R.layout.row_list);
inflater = (LayoutInflater)MainActivity.activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

[MENTION=439709]override[/MENTION]
public int getCount() {
return items.length;
}

[MENTION=923100]Nonnu[/MENTION]ll
[MENTION=439709]override[/MENTION]
public View getView(int position, View convertView, ViewGroup parent) {

row = convertView ;
if(convertView == null){
row = inflater.inflate(R.layout.row_list,parent,false);
}

row_list_img1 = (ImageView)row.findViewById(R.id.row_list_img1);
row_list_title = (TextView) row.findViewById(R.id.row_list_title);
row_list_price = (TextView)row.findViewById(R.id.row_list_price);
row_list_time = (TextView)row.findViewById(R.id.row_list_time);
row_list_card = (CardView) row.findViewById(R.id.row_list_card);

final HashMap<String , Object> hash_get = (HashMap<String , Object>) hash_all.get(position);

row_list_title.setText(hash_get.get("Title").toString());
row_list_price.setText(hash_get.get("Price").toString()+" تومان");

if(Integer.parseInt(hash_get.get("Date").toString())<=59){
if(hash_get.get("Date").toString().equals("0") || hash_get.get("Date").toString().equals("1")){
row_list_time.setText("همین الان");
}else {
row_list_time.setText(hash_get.get("Date").toString()+" دقیقه پیش");
}
}else if(Integer.parseInt(hash_get.get("Date").toString())>=60 && Integer.parseInt(hash_get.get("Date").toString())<=1439){
int h = Integer.parseInt(hash_get.get("Date").toString())/60;
row_list_time.setText(h+" ساعت پیش");
}else if(Integer.parseInt(hash_get.get("Date").toString())>=1440 && Integer.parseInt(hash_get.get("Date").toString())<=43199){
int hh = Integer.parseInt(hash_get.get("Date").toString())/60/24;
row_list_time.setText(hh+" روز پیش");
}else if(Integer.parseInt(hash_get.get("Date").toString())>=43200 && Integer.parseInt(hash_get.get("Date").toString())<=518339){
int hhh = Integer.parseInt(hash_get.get("Date").toString())/60/24/30;
row_list_time.setText(hhh+" ماه پیش");
}else if(Integer.parseInt(hash_get.get("Date").toString())>=518340){
int hhhh = Integer.parseInt(hash_get.get("Date").toString())/60/24/30/12;
row_list_time.setText(hhhh+" سال پیش");
}

Picasso.with(MainActivity.activity)
.load(hash_get.get("Img1").toString())
.placeholder(R.mipmap.ic_launcher)
.into(row_list_img1);

row_list_card.setOnClickListener(new View.OnClickListener() {
[MENTION=439709]override[/MENTION]
public void onClick(View v) {

Intent intent = new Intent(MainActivity.activity,Detail_Banners.class);
intent.putExtra("ID",hash_get.get("ID").toString());
intent.putExtra("Username",hash_get.get("Username").toString());
intent.putExtra("Title",hash_get.get("Title").toString());
intent.putExtra("Descript",hash_get.get("Descript").toString());
intent.putExtra("Price",hash_get.get("Price").toString());
intent.putExtra("Tell",hash_get.get("Tell").toString());
intent.putExtra("Email",hash_get.get("Email").toString());
intent.putExtra("City",hash_get.get("City").toString());
intent.putExtra("Cate",hash_get.get("Cate").toString());
intent.putExtra("Img1",hash_get.get("Img1").toString());
intent.putExtra("Img2",hash_get.get("Img2").toString());
intent.putExtra("Img3",hash_get.get("Img3").toString());
intent.putExtra("Date",hash_get.get("Date").toString());
startActivity(intent);

}
});

return row;
}
}
private void saeed(){

}
private void CheckNet(){

boolean connect = false ;

ConnectivityManager connectivityManager = (ConnectivityManager)MainActivity.activity.getSystemService(Context.CONNECTIVITY_SERVICE);
if(connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED
|| connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED){
connect = true ;
}else {
connect = false ;
}

if(connect==true){
try {
get_banners(page);
}catch (Exception e){
e.printStackTrace();
}
}else {
new MaterialDialog.Builder(MainActivity.activity)
.title("عدم اتصال به اینترنت")
.content("لطفا اتصال به اینترنت خود را بررسی کنید")
.positiveText("بررسی مجدد")
.negativeText("خروج")
.callback(new MaterialDialog.ButtonCallback() {
[MENTION=439709]override[/MENTION]
public void onNegative(MaterialDialog dialog) {
super.onNegative(dialog);
MainActivity.activity.finish();
}

[MENTION=439709]override[/MENTION]
public void onPositive(MaterialDialog dialog) {
super.onPositive(dialog);
CheckNet();
}
})
.show();
}

}

// Development by SmartMob (Manager : Mohammad Mokhles)
}

althing is ok but when i havent internet connection it will be force close