如何显示敬酒消息中没有扩展活动课 [英] how to show toast message in not extend activity class

查看:114
本文介绍了如何显示敬酒消息中没有扩展活动课的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,这是我的辅助类,其中i检查内部连接和xml paersing和使用这个类到另一个活动时连接的服务器工作正常,但是当服务器未响应或无效的输入code是爆炸意外停止我的问题是找出asyntask来解决这个ISSE但我的问题是我怎么可以在这个code使用的AsyncTask?或如何显示敬酒消息,如果服务器没有响应的错误信息连接错误aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa被显示在日志,但土司我该怎么办,所以我不应用服务器时,没有响应爆炸没有显示?任何想法?

 公共类AgAppHelperMethods {     私有静态最后弦乐LOG_TAG = NULL;     私有静态AgAppHelperMethods例如= NULL;     公共静态字符串varMobileNo;
     公共静态字符串varPinNo;
     的String [] [] xmlRespone = NULL;     公共静态字符串的getURL(){
         字符串URL =htt​​ps://demo.accessgroup.mobi/;
         返回URL;
     }     公共静态的String [] [] AgAppXMLParser(字符串parUrl){
         串_node,_Element;
         的String [] [] xmlRespone = NULL;
         尝试{
             字符串URL = AgAppHelperMethods.getUrl()+ parUrl;
             网址finalUrl =新的URL(网址);
             DBF的DocumentBuilderFactory =
                 DocumentBuilderFactory.newInstance();
             的DocumentBuilder分贝= dbf.newDocumentBuilder();
             文档的文档= db.parse(新的InputSource(finalUrl.openStream()));
             doc.getDocumentElement()正常化()。             节点列表清单= doc.getElementsByTagName(*);
             _node =新的String();
             _Element =新的String();
             xmlRespone =新的String [list.getLength()] [2];             的for(int i = 0; I< list.getLength();我++){
                 节点值= list.item(ⅰ).getChildNodes()项(0)。
                 _node = list.item(ⅰ).getNodeName();
                 _Element = value.getNodeValue();
                 xmlRespone [I] [0] = _node;
                 xmlRespone [I] [1] = _Element;
             } //结束了
         } //结束试
         赶上(例外五){
             // Toast.makeText(背景下,错误的服务器没有响应+
             e.getMessage(),Toast.LENGTH_LONG).show();
         Log.e(LOG_TAG,连接错误aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
             E);
         //做别的事情,如果想要的。
     }
     返回xmlRespone;
 }


解决方案

创建一个全局变量,如:

 上下文mContext;

然后一个构造函数添加到您的类,在其中您接受语境的参数,并分配它mContext喜欢的:

 公共AgAppHelperMethods(上下文的背景下){
      mContext =背景;
}

在您的活动创建一个对象,如:

  AgAppHelperMethods帮手=新AgAppHelperMethods(getBaseContext());

最后,为了显示你的吐司使用:

  Toast.makeText(mContext,错误的服务器没有响应+ e.getMessage(),Toast.LENGTH_LONG).show();

hi this is my helper class where i check internal connection and xml paersing and use this class to another activity the problem is when server connected is working fine but when server not responding or invalid input code is blast stop unexpectedly i find out asyntask to resolve this isse but my problem is how can i used AsyncTask in this code? or how to show toast message if server not responding error message Connection Error aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa is show on log but not show on toast what do i do so my application not blast when server not respond? any idea?

 public class AgAppHelperMethods {

     private static final String LOG_TAG = null;

     private static AgAppHelperMethods instance = null;

     public static String varMobileNo;
     public static String varPinNo;
     String[][] xmlRespone = null;

     public static String getUrl() {
         String url = "https://demo.accessgroup.mobi/";
         return url;
     }

     public static String[][] AgAppXMLParser(String parUrl) {
         String _node, _element;
         String[][] xmlRespone = null;
         try {
             String url = AgAppHelperMethods.getUrl() + parUrl;
             URL finalUrl = new URL(url);
             DocumentBuilderFactory dbf =
                 DocumentBuilderFactory.newInstance();
             DocumentBuilder db = dbf.newDocumentBuilder();
             Document doc = db.parse(new InputSource(finalUrl.openStream()));
             doc.getDocumentElement().normalize();

             NodeList list = doc.getElementsByTagName("*");
             _node = new String();
             _element = new String();
             xmlRespone = new String[list.getLength()][2];

             for (int i = 0; i < list.getLength(); i++) {
                 Node value = list.item(i).getChildNodes().item(0);
                 _node = list.item(i).getNodeName();
                 _element = value.getNodeValue();
                 xmlRespone[i][0] = _node;
                 xmlRespone[i][1] = _element;
             } //end for
         } //end try
         catch (Exception e) {
             // Toast.makeText(context, "error  server not responding " +  
             e.getMessage(), Toast.LENGTH_LONG).show();
         Log.e(LOG_TAG, "Connection Error aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
             e);
         // Do something else, if wanted.
     }
     return xmlRespone;
 }

解决方案

Create a global variable like:

Context mContext;

Then add a constructor to your class, in which you accept a Context parameter and assign it to mContext like:

public AgAppHelperMethods(Context context) {
      mContext = context;
}

Create an object in your Activity like:

AgAppHelperMethods helper = new AgAppHelperMethods(getBaseContext());

Finally, to show your Toast use:

 Toast.makeText(mContext, "error  server not responding " + e.getMessage(), Toast.LENGTH_LONG).show();

这篇关于如何显示敬酒消息中没有扩展活动课的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆