嗨!我試圖在網絡關閉或服務器沒有響應時顯示消息。我的消息在LOG中可見,但不顯示在屏幕上(未烤)。我有一個示例代碼工作正常,但我的代碼不是。吐司沒有在catch catch中顯示
import android.view.View.OnKeyListener;
public class AgAppHelperMethods extends Activity {
private static final String LOG_TAG = null;
private static AgAppHelperMethods instance = null;
public static String varMobileNo;
public static String varPinNo;
String[][] xmlRespone = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.agapphelpermethods);
}
protected AgAppHelperMethods() {}
public static AgAppHelperMethods getInstance()
{
if(instance == null)
{
instance = new AgAppHelperMethods();
}
return instance;
}
public static String getUrl()
{
String url = "https://demo.accessgroup.mobi/";
return url;
}
public 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;
}
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(), "error server not responding " + e.getMessage(),
Toast.LENGTH_SHORT).show();
Log.e(LOG_TAG, "CONNECTION ERROR FUNDAMO SERVER NOT RESPONDING", e);
}
}
}
如何在屏幕上顯示我的敬酒信息?謝謝。
嘗試使用'AgAppHelperMethods.this',而不是'getApplicationContext()'在'Toast' – Praveenkumar 2012-07-12 06:49:14
請不要問人們對於他們的電子郵件地址。這裏沒有人是你的私人幫手。 – 2012-07-12 07:20:19