Android 应用程序强制关闭而不使用internet JSON

Android 应用程序强制关闭而不使用internet JSON,android,json,Android,Json,我在第一个活动中使用json制作了一个应用程序,但是当应用程序在没有连接互联网的情况下打开时,应用程序会“强制关闭”,我不知道该怎么做才能避免这个错误,帮助,我是android和java上的新手 公共类MainActivity扩展了ActionBarActivity{ String TITLES[] = {"Que es CMX","Ejecutivos(as)","Nuestros Servicios","Soluciones a tu Medida","Certificaciones Vig

我在第一个活动中使用json制作了一个应用程序,但是当应用程序在没有连接互联网的情况下打开时,应用程序会“强制关闭”,我不知道该怎么做才能避免这个错误,帮助,我是android和java上的新手

公共类MainActivity扩展了ActionBarActivity{

String TITLES[] = {"Que es CMX","Ejecutivos(as)","Nuestros Servicios","Soluciones a tu Medida","Certificaciones Vigentes", "Cursos Online", "", "", "", ""};

int ICONS[] = {R.mipmap.organization,R.mipmap.conference,R.mipmap.services,R.mipmap.approval,R.mipmap.diploma1,R.mipmap.donate,R.id.linea,R.id.linea,R.id.linea,R.mipmap.home};

String NAME = "John Doe";
String EMAIL = "johndoe@cmx.org.mx";
int PROFILE = R.drawable.profile1;

private Toolbar toolbar;                              // Declaring the Toolbar Object

RecyclerView mRecyclerView;                           // Declaring RecyclerView
RecyclerView.Adapter mAdapter;                        // Declaring Adapter For Recycler View
RecyclerView.LayoutManager mLayoutManager;            // Declaring Layout Manager as a linear layout manager
DrawerLayout Drawer;                                  // Declaring DrawerLayout

ActionBarDrawerToggle mDrawerToggle;                  // Declaring Action Bar Drawer Toggle
// Declare Variables
JSONObject jsonobject;
JSONArray jsonarray;
ListView listview;
ListViewAdapter adapter;
ProgressDialog mProgressDialog;
ArrayList<HashMap<String, String>> arraylist;
static String RANK = "title";
static String COUNTRY = "place";
static String POPULATION = "date";
static String CONTENT1 = "content1";
static String CONTENT2 = "content2";
static String FLAG = "imagen";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get the view from listview_main.xml
    setContentView(R.layout.listview_main);
    // Execute DownloadJSON AsyncTask
    new DownloadJSON().execute();

    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);

    setTitle(R.string.title_activity_main);



    mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View

    mRecyclerView.setHasFixedSize(true);                            // Letting the system know that the list objects are of fixed size

    mAdapter = new MyAdapter(TITLES,ICONS,NAME,EMAIL,PROFILE,this);       // Creating the Adapter of MyAdapter class(which we are going to see in a bit)
    // And passing the titles,icons,header view name, header view email,
    // and header view profile picture

    mRecyclerView.setAdapter(mAdapter);                              // Setting the adapter to RecyclerView

    final GestureDetector mGestureDetector = new GestureDetector(MainActivity.this, new GestureDetector.SimpleOnGestureListener() {

        @Override public boolean onSingleTapUp(MotionEvent e) {
            return true;
        }

    });


    mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
        @Override
        public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
            View child = recyclerView.findChildViewUnder(motionEvent.getX(),motionEvent.getY());



            if(child !=null && mGestureDetector.onTouchEvent(motionEvent)){
                Drawer.closeDrawers();

                if (recyclerView.getChildPosition(child) == 0) {
                    Intent intent = new Intent(MainActivity.this, Profile.class);
                    startActivity(intent);
                    finish();
                }else if
                        (recyclerView.getChildPosition(child) == 1) {
                    Intent intent = new Intent(MainActivity.this, CMX.class);
                    startActivity(intent);
                    finish();
                }else if
                        (recyclerView.getChildPosition(child) == 2) {
                    Intent intent = new Intent(MainActivity.this, Ejecutivos.class);
                    startActivity(intent);
                    finish();
                }else if
                        (recyclerView.getChildPosition(child) == 3){
                    Intent intent = new Intent(MainActivity.this, Servicios.class);
                    startActivity(intent);
                    finish();
                }else if
                        (recyclerView.getChildPosition(child) == 4){
                    Intent intent = new Intent(MainActivity.this, Soluciones.class);
                    startActivity(intent);
                    finish();
                }else if
                        (recyclerView.getChildPosition(child) == 5) {
                    Intent intent = new Intent(MainActivity.this, Certificaciones.class);
                    startActivity(intent);
                    finish();
                }else if
                        (recyclerView.getChildPosition(child) == 6){
                    Intent intent = new Intent(MainActivity.this, Web.class);
                    startActivity(intent);
                    finish();
                }else if
                        (recyclerView.getChildPosition(child) == 8 ){
                    Intent intent = new Intent(MainActivity.this, MainActivity.class);
                    startActivity(intent);
                    finish();
                }

                return true;

            }

            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {

        }
    });


    mLayoutManager = new LinearLayoutManager(this);                 // Creating a layout Manager

    mRecyclerView.setLayoutManager(mLayoutManager);                 // Setting the layout Manager


    Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);        // Drawer object Assigned to the view
    mDrawerToggle = new ActionBarDrawerToggle(this,Drawer,toolbar,R.string.openDrawer,R.string.closeDrawer){

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            // code here will execute once the drawer is opened( As I dont want anything happened whe drawer is
            // open I am not going to put anything here)
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            // Code here will execute once drawer is closed
        }



    }; // Drawer Toggle Object Made
    Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle
    mDrawerToggle.syncState();               // Finally we set the drawer toggle sync State
}

// DownloadJSON AsyncTask
private class DownloadJSON extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Create a progressdialog
        mProgressDialog = new ProgressDialog(MainActivity.this);
        // Set progressdialog message
        mProgressDialog.setMessage("Cargando...");
        mProgressDialog.setIndeterminate(false);
        // Show progressdialog
        mProgressDialog.show();
    }


    @Override
    protected Void doInBackground(Void... params) {
        // Create an array
        arraylist = new ArrayList<HashMap<String, String>>();
        // Retrieve JSON Objects from the given URL address
        jsonobject = JSONfunctions.getJSONfromURL("http://cmx.org.mx/wp-content/uploads/json.txt");

        try {
            // Locate the array name in JSON
            jsonarray = jsonobject.getJSONArray("posts");

            for (int i = 0; i < jsonarray.length(); i++) {
                HashMap<String, String> map = new HashMap<String, String>();
                jsonobject = jsonarray.getJSONObject(i);
                // Retrive JSON Objects
                map.put("title", jsonobject.getString("title"));
                map.put("place", jsonobject.getString("place"));
                map.put("date", jsonobject.getString("date"));
                map.put("content1", jsonobject.getString("content1"));
                map.put("content2", jsonobject.getString("content2"));
                map.put("imagen", jsonobject.getString("imagen"));
                // Set the JSON Objects into the array
                arraylist.add(map);
            }
        } catch (JSONException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void args) {
        // Locate the listview in listview_main.xml
        listview = (ListView) findViewById(R.id.listview);
        // Pass the results into ListViewAdapter.java
        adapter = new ListViewAdapter(MainActivity.this, arraylist);
        // Set the adapter to the ListView
        listview.setAdapter(adapter);
        // Close the progressdialog
        mProgressDialog.dismiss();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

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();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }

    switch (item.getItemId()) {
        // Respond to the action bar's Up/Home button
        case R.id.about:

            Intent intent = new Intent(MainActivity.this, About.class);
            startActivity(intent);

            return true;
    }
    return super.onOptionsItemSelected(item);
}
-编辑

日志:

更新1:

        @Override
    protected Void doInBackground(Void... params) {
        // Create an array
        arraylist = new ArrayList<HashMap<String, String>>();
        // Retrieve JSON Objects from the given URL address
        jsonobject = JSONfunctions.getJSONfromURL("http://cmx.org.mx/wp-content/uploads/json.txt");

    if(jsonobject==null){
        Toast.makeText(getApplicationContext(), "No Internet", Toast.LENGTH_LONG).show();
    }else{

        try {
            // Locate the array name in JSON
            jsonarray = jsonobject.getJSONArray("posts");

            for (int i = 0; i < jsonarray.length(); i++) {
                HashMap<String, String> map = new HashMap<String, String>();
                jsonobject = jsonarray.getJSONObject(i);
                // Retrive JSON Objects
                map.put("title", jsonobject.getString("title"));
                map.put("place", jsonobject.getString("place"));
                map.put("date", jsonobject.getString("date"));
                map.put("content1", jsonobject.getString("content1"));
                map.put("content2", jsonobject.getString("content2"));
                map.put("imagen", jsonobject.getString("imagen"));
                // Set the JSON Objects into the array
                arraylist.add(map);
            }
        } catch (JSONException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
    }
        return null;
    }
@覆盖
受保护的Void doInBackground(Void…参数){
//创建一个数组
arraylist=新的arraylist();
//从给定的URL地址检索JSON对象
jsonobject=JSONfunctions.getJSONfromURL(“http://cmx.org.mx/wp-content/uploads/json.txt");
if(jsonobject==null){
Toast.makeText(getApplicationContext(),“无互联网”,Toast.LENGTH_LONG.show();
}否则{
试一试{
//在JSON中找到数组名称
jsonarray=jsonobject.getJSONArray(“posts”);
for(int i=0;i
MyAdapter:

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {

private static final int TYPE_HEADER = 0;  // Declaring Variable to Understand which View is being worked on
// IF the view under inflation and population is header or Item
private static final int TYPE_ITEM = 1;

private String mNavTitles[]; // String Array to store the passed titles Value from MainActivity.java
private int mIcons[];       // Int Array to store the passed icons resource value from MainActivity.java

private String name;        //String Resource for header View Name
private int profile;        //int Resource for header view profile picture
private String email;       //String Resource for header view email
Context context;


// Creating a ViewHolder which extends the RecyclerView View Holder
// ViewHolder are used to to store the inflated views in order to recycle them

public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    int Holderid;

    TextView textView;
    ImageView imageView;
    ImageView profile;
    TextView Name;
    TextView email;
    Context contxt;


    public ViewHolder(View itemView,int ViewType,Context c) {                 // Creating ViewHolder Constructor with View and viewType As a parameter
        super(itemView);
        contxt = c;
        itemView.setClickable(true);
        itemView.setOnClickListener(this);


        // Here we set the appropriate view in accordance with the the view type as passed when the holder object is created

        if(ViewType == TYPE_ITEM) {
            textView = (TextView) itemView.findViewById(R.id.rowText); // Creating TextView object with the id of textView from item_row.xml
            imageView = (ImageView) itemView.findViewById(R.id.rowIcon);// Creating ImageView object with the id of ImageView from item_row.xml
            Holderid = 1;                                               // setting holder id as 1 as the object being populated are of type item row
        }
        else{


            Name = (TextView) itemView.findViewById(R.id.name);         // Creating Text View object from header.xml for name
            email = (TextView) itemView.findViewById(R.id.email);       // Creating Text View object from header.xml for email
            profile = (ImageView) itemView.findViewById(R.id.circleView);// Creating Image view object from header.xml for profile pic
            Holderid = 0;                                                // Setting holder id = 0 as the object being populated are of type header view
        }
    }

    @Override
    public void onClick(View v) {

        Toast.makeText(contxt, "The Item Clicked is: " + getPosition(), Toast.LENGTH_SHORT).show();

    }

    }



MyAdapter(String Titles[],int Icons[],String Name,String Email, int Profile, Context passedContext){ // MyAdapter Constructor with titles and icons parameter
    // titles, icons, name, email, profile pic are passed from the main activity as we
        mNavTitles = Titles;                //have seen earlier
    mIcons = Icons;
    name = Name;
    email = Email;
    profile = Profile;
    this.context = passedContext;    //here we assign those passed values to the values we declared here
    //in adapter

}



//Below first we ovverride the method onCreateViewHolder which is called when the ViewHolder is
//Created, In this method we inflate the item_row.xml layout if the viewType is Type_ITEM or else we inflate header.xml
// if the viewType is TYPE_HEADER
// and pass it to the view holder

@Override
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    if (viewType == TYPE_ITEM) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_row,parent,false); //Inflating the layout

        ViewHolder vhItem = new ViewHolder(v,viewType,context); //Creating ViewHolder and passing the object of type view

        return vhItem; // Returning the created object

        //inflate your layout and pass it to view holder

    } else if (viewType == TYPE_HEADER) {

        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.header,parent,false); //Inflating the layout

        ViewHolder vhHeader = new ViewHolder(v,viewType,context); //Creating ViewHolder and passing the object of type view

        return vhHeader; //returning the object created


    }
    return null;

}

//Next we override a method which is called when the item in a row is needed to be displayed, here the int position
// Tells us item at which position is being constructed to be displayed and the holder id of the holder object tell us
// which view type is being created 1 for item row
@Override
public void onBindViewHolder(MyAdapter.ViewHolder holder, int position) {
    if(holder.Holderid ==1) {                              // as the list view is going to be called after the header view so we decrement the
        // position by 1 and pass it to the holder while setting the text and image
        holder.textView.setText(mNavTitles[position - 1]); // Setting the Text with the array of our Titles
        holder.imageView.setImageResource(mIcons[position -1]);// Settimg the image with array of our icons
    }
    else{

        holder.profile.setImageResource(profile);           // Similarly we set the resources for header view
        holder.Name.setText(name);
        holder.email.setText(email);
    }
}

// This method returns the number of items present in the list
@Override
public int getItemCount() {
    return mNavTitles.length+1; // the number of items in the list will be +1 the titles including the header view.
}


// Witht the following method we check what type of view is being passed
@Override
public int getItemViewType(int position) {
    if (isPositionHeader(position))
        return TYPE_HEADER;

    return TYPE_ITEM;
}

private boolean isPositionHeader(int position) {
    return position == 0;
}
公共类MyAdapter扩展了RecyclerView.Adapter{ private static final int TYPE_HEADER=0;//声明变量以了解正在处理哪个视图 //如果“通货膨胀和人口”下的视图是标题或项目 私有静态最终整数类型\ u项=1; 私有字符串mNavTitles[];//用于存储MainActivity.java中传递的标题值的字符串数组 private int mIcons[];//用于存储MainActivity.java中传递的图标资源值的int数组 私有字符串名称;//头视图名称的字符串资源 private int profile;//标题视图配置文件图片的int资源 私有字符串电子邮件;//标题视图电子邮件的字符串资源 语境; //创建扩展RecyclerView视图保持架的视图保持架 //ViewHolder用于存储膨胀的视图,以便对其进行回收 公共静态类ViewHolder扩展了RecyclerView.ViewHolder实现了View.OnClickListener{ int-Holderid; 文本视图文本视图; 图像视图图像视图; 图像视图剖面; 文本视图名称; TextView电子邮件; 语境语境; 公共ViewHolder(View itemView、int ViewType、Context c){//使用View和ViewType作为参数创建ViewHolder构造函数 超级(项目视图); contxt=c; itemView.setClickable(真); setOnClickListener(这个); //在这里,我们根据创建holder对象时传递的视图类型设置适当的视图 if(ViewType==类型\项){ textView=(textView)itemView.findViewById(R.id.rowText);//从item_row.xml创建id为textView的textView对象 imageView=(imageView)itemView.findViewById(R.id.rowIcon);//从item_row.xml创建具有imageView id的imageView对象 Holderid=1;//将holder id设置为1,因为正在填充的对象的类型为item row } 否则{ Name=(TextView)itemView.findViewById(R.id.Name);//从header.xml为Name创建文本视图对象 email=(TextView)itemView.findViewById(R.id.email);//从header.xml为电子邮件创建文本视图对象 profile=(ImageView)itemView.findViewById(R.id.circleView);//从header.xml为profile pic创建图像视图对象 Holderid=0;//设置holder id=0,因为正在填充的对象属于header视图类型 } } @凌驾 公共void onClick(视图v){ Toast.makeText(contxt),单击的项目是:“+getPosition(),Toast.LENGTH\u SHORT.show(); } } MyAdapter(字符串标题[],整数图标[],字符串名称,字符串电子邮件,整数配置文件,上下文传递上下文){//MyAdapter构造函数,带有标题和图标参数 //标题、图标、姓名、电子邮件、个人资料图片都是在我们访问时从主要活动中传递过来的 mNavTitles=Titles;//以前见过 mIcons=图标; 名称=名称; 电子邮件=电子邮件; 外形=外形; this.context=passedContext;//这里我们将这些传递的值分配给我们在这里声明的值 //输入适配器 } //在下面,我们首先讨论了在创建ViewHolder时调用的方法onCreateViewHolder //创建时,在此方法中,如果viewType为Type\u item,则膨胀item_row.xml布局,否则膨胀header.xml //如果视图类型为类型_HEADER //并将其传递给视图保持器 @凌驾 public MyAdapter.ViewHolder onCreateViewHolder(视图组父级,int-viewType){ if(viewType==类型\项){ View v=LayoutInflater.from(parent.getContext()).inflate(R.layout.item_行,parent,false);//充气布局 ViewHolder vhItem=新的ViewHolder(v,viewType,context);//创建ViewHolder并传递view类型的对象 return vhItem;//返回创建的对象 //充气布局并将其传递给视图保持架 }else if(viewType==类型\标题){ View v=LayoutInflater.from(parent.getContext()).flate(R.layout.header,parent,false);//对布局进行充气 ViewHolder vhHeader=新的ViewHolder(v、viewType、co
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {

private static final int TYPE_HEADER = 0;  // Declaring Variable to Understand which View is being worked on
// IF the view under inflation and population is header or Item
private static final int TYPE_ITEM = 1;

private String mNavTitles[]; // String Array to store the passed titles Value from MainActivity.java
private int mIcons[];       // Int Array to store the passed icons resource value from MainActivity.java

private String name;        //String Resource for header View Name
private int profile;        //int Resource for header view profile picture
private String email;       //String Resource for header view email
Context context;


// Creating a ViewHolder which extends the RecyclerView View Holder
// ViewHolder are used to to store the inflated views in order to recycle them

public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    int Holderid;

    TextView textView;
    ImageView imageView;
    ImageView profile;
    TextView Name;
    TextView email;
    Context contxt;


    public ViewHolder(View itemView,int ViewType,Context c) {                 // Creating ViewHolder Constructor with View and viewType As a parameter
        super(itemView);
        contxt = c;
        itemView.setClickable(true);
        itemView.setOnClickListener(this);


        // Here we set the appropriate view in accordance with the the view type as passed when the holder object is created

        if(ViewType == TYPE_ITEM) {
            textView = (TextView) itemView.findViewById(R.id.rowText); // Creating TextView object with the id of textView from item_row.xml
            imageView = (ImageView) itemView.findViewById(R.id.rowIcon);// Creating ImageView object with the id of ImageView from item_row.xml
            Holderid = 1;                                               // setting holder id as 1 as the object being populated are of type item row
        }
        else{


            Name = (TextView) itemView.findViewById(R.id.name);         // Creating Text View object from header.xml for name
            email = (TextView) itemView.findViewById(R.id.email);       // Creating Text View object from header.xml for email
            profile = (ImageView) itemView.findViewById(R.id.circleView);// Creating Image view object from header.xml for profile pic
            Holderid = 0;                                                // Setting holder id = 0 as the object being populated are of type header view
        }
    }

    @Override
    public void onClick(View v) {

        Toast.makeText(contxt, "The Item Clicked is: " + getPosition(), Toast.LENGTH_SHORT).show();

    }

    }



MyAdapter(String Titles[],int Icons[],String Name,String Email, int Profile, Context passedContext){ // MyAdapter Constructor with titles and icons parameter
    // titles, icons, name, email, profile pic are passed from the main activity as we
        mNavTitles = Titles;                //have seen earlier
    mIcons = Icons;
    name = Name;
    email = Email;
    profile = Profile;
    this.context = passedContext;    //here we assign those passed values to the values we declared here
    //in adapter

}



//Below first we ovverride the method onCreateViewHolder which is called when the ViewHolder is
//Created, In this method we inflate the item_row.xml layout if the viewType is Type_ITEM or else we inflate header.xml
// if the viewType is TYPE_HEADER
// and pass it to the view holder

@Override
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    if (viewType == TYPE_ITEM) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_row,parent,false); //Inflating the layout

        ViewHolder vhItem = new ViewHolder(v,viewType,context); //Creating ViewHolder and passing the object of type view

        return vhItem; // Returning the created object

        //inflate your layout and pass it to view holder

    } else if (viewType == TYPE_HEADER) {

        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.header,parent,false); //Inflating the layout

        ViewHolder vhHeader = new ViewHolder(v,viewType,context); //Creating ViewHolder and passing the object of type view

        return vhHeader; //returning the object created


    }
    return null;

}

//Next we override a method which is called when the item in a row is needed to be displayed, here the int position
// Tells us item at which position is being constructed to be displayed and the holder id of the holder object tell us
// which view type is being created 1 for item row
@Override
public void onBindViewHolder(MyAdapter.ViewHolder holder, int position) {
    if(holder.Holderid ==1) {                              // as the list view is going to be called after the header view so we decrement the
        // position by 1 and pass it to the holder while setting the text and image
        holder.textView.setText(mNavTitles[position - 1]); // Setting the Text with the array of our Titles
        holder.imageView.setImageResource(mIcons[position -1]);// Settimg the image with array of our icons
    }
    else{

        holder.profile.setImageResource(profile);           // Similarly we set the resources for header view
        holder.Name.setText(name);
        holder.email.setText(email);
    }
}

// This method returns the number of items present in the list
@Override
public int getItemCount() {
    return mNavTitles.length+1; // the number of items in the list will be +1 the titles including the header view.
}


// Witht the following method we check what type of view is being passed
@Override
public int getItemViewType(int position) {
    if (isPositionHeader(position))
        return TYPE_HEADER;

    return TYPE_ITEM;
}

private boolean isPositionHeader(int position) {
    return position == 0;
}
 @Override
protected Void doInBackground(Void... params) {
    // Create an array
    arraylist = new ArrayList<HashMap<String, String>>();
    // Retrieve JSON Objects from the given URL address
    jsonobject = JSONfunctions.getJSONfromURL("http://cmx.org.mx/wp-content/uploads/json.txt");

    if(jsonobject==null){
        Intent intent = new Intent(MainActivity.this, CMX.class);
        startActivity(intent);
        finish();
}else{

    try {
        // Locate the array name in JSON
        jsonarray = jsonobject.getJSONArray("posts");