"unterminated entity ref" Exception while working with DomParser in Android

WebService Response Looks:


---------------------trimString--------------------------------
<restaurant>
<name>
<sid>1</sid>
<restcode>1</restcode>
<restname>Garden Restaurant</restname>
<status>1</status>
</name>

<name>
<sid>2</sid>
<restcode>2</restcode>
<restname>Bar & Restaurant</restname>
<status>1</status>
</name>
</restaurant>




---------------------------------------------------------------------------------------------------------------------
LogCat ErrorLog Data :::

05-11 11:22:07.783: E/Error:(1044): unterminated entity ref (position:ENTITY_REF @11:19 in java.io.StringReader@40d7e790) 
05-11 11:22:07.823: I/System.out(1044): -------doc-------null
05-11 11:22:07.823: W/dalvikvm(1044): threadid=11: thread exiting with uncaught exception (group=0x40a70930)
05-11 11:22:07.833: E/AndroidRuntime(1044): FATAL EXCEPTION: Thread-87
05-11 11:22:07.833: E/AndroidRuntime(1044): java.lang.NullPointerException
05-11 11:22:07.833: E/AndroidRuntime(1044): at org.maxima.kot.PLLoginScreen$1.run(PLLoginScreen.java:179)
05-11 11:22:07.833: E/AndroidRuntime(1044): at java.lang.Thread.run(Thread.java:856)
05-11 11:22:07.843: W/Trace(1044): Unexpected value from nativeGetEnabledTags: 0
05-11 11:22:07.863: W/Trace(1044): Unexpected value from nativeGetEnabledTags: 0
05-11 11:22:07.873: I/Choreographer(1044): Skipped 210 frames!  The application may be doing too much work on its main thread.
05-11 11:22:16.742: W/Trace(1044): Unexpected value from nativeGetEnabledTags: 0
05-11 11:22:16.742: W/Trace(1044): Unexpected value from nativeGetEnabledTags: 0
05-11 11:22:16.853: W/Trace(1044): Unexpected value from nativeGetEnabledTags: 0
05-11 11:22:16.853: W/Trace(1044): Unexpected value from nativeGetEnabledTags: 0
05-11 11:22:16.884: W/Trace(1044): Unexpected value from nativeGetEnabledTags: 0
05-11 11:22:16.904: W/Trace(1044): Unexpected value from nativeGetEnabledTags: 0
05-11 11:22:16.933: W/Trace(1044): Unexpected value from nativeGetEnabledTags: 0
05-11 11:22:17.383: E/WindowManager(1044): Activity org.maxima.kot.PLLoginScreen has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d53f30 V.E..... R.....ID 0,0-139,88} that was originally added here
05-11 11:22:17.383: E/WindowManager(1044): android.view.WindowLeaked: Activity org.maxima.kot.PLLoginScreen has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d53f30 V.E..... R.....ID 0,0-139,88} that was originally added here
05-11 11:22:17.383: E/WindowManager(1044): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
05-11 11:22:17.383: E/WindowManager(1044): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
05-11 11:22:17.383: E/WindowManager(1044): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
05-11 11:22:17.383: E/WindowManager(1044): at android.app.Dialog.show(Dialog.java:281)
05-11 11:22:17.383: E/WindowManager(1044): at android.app.ProgressDialog.show(ProgressDialog.java:116)
05-11 11:22:17.383: E/WindowManager(1044): at android.app.ProgressDialog.show(ProgressDialog.java:99)
05-11 11:22:17.383: E/WindowManager(1044): at org.maxima.kot.SharedVariables.showActivityIndicator(SharedVariables.java:42)
05-11 11:22:17.383: E/WindowManager(1044): at org.maxima.kot.PLLoginScreen.loginBtnonClick(PLLoginScreen.java:145)
05-11 11:22:17.383: E/WindowManager(1044): at java.lang.reflect.Method.invokeNative(Native Method)
05-11 11:22:17.383: E/WindowManager(1044): at java.lang.reflect.Method.invoke(Method.java:511)
05-11 11:22:17.383: E/WindowManager(1044): at android.view.View$1.onClick(View.java:3592)
05-11 11:22:17.383: E/WindowManager(1044): at android.view.View.performClick(View.java:4202)
05-11 11:22:17.383: E/WindowManager(1044): at android.view.View$PerformClick.run(View.java:17340)
05-11 11:22:17.383: E/WindowManager(1044): at android.os.Handler.handleCallback(Handler.java:725)
05-11 11:22:17.383: E/WindowManager(1044): at android.os.Handler.dispatchMessage(Handler.java:92)
05-11 11:22:17.383: E/WindowManager(1044): at android.os.Looper.loop(Looper.java:137)
05-11 11:22:17.383: E/WindowManager(1044): at android.app.ActivityThread.main(ActivityThread.java:5039)
05-11 11:22:17.383: E/WindowManager(1044): at java.lang.reflect.Method.invokeNative(Native Method)
05-11 11:22:17.383: E/WindowManager(1044): at java.lang.reflect.Method.invoke(Method.java:511)
05-11 11:22:17.383: E/WindowManager(1044): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-11 11:22:17.383: E/WindowManager(1044): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-11 11:22:17.383: E/WindowManager(1044): at dalvik.system.NativeStart.main(Native Method)
05-11 11:22:17.412: W/Trace(1044): Unexpected value from nativeGetEnabledTags: 0
05-11 11:22:17.603: I/Choreographer(1044): Skipped 228 frames!  The application may be doing too much work on its main thread.
05-11 11:27:08.485: W/IInputConnectionWrapper(1044): showStatusIcon on inactive InputConnection
05-11 11:27:08.485: I/Process(1044): Sending signal. PID: 1044 SIG: 9

---------------------------------------------------------------------------------------------------------------

MyJavaCode:


//if internet is there...
if(SharedVariables.checkInternetConnection(this))
{
progressDialog =SharedVariables.showActivityIndicator("Logging In...", PLLoginScreen.this);//ProgressDialog.show(PLLoginScreen.this, "", "Logging In...");
Thread thread=new Thread(new Runnable() {
@Override
public void run() {

try {
  HttpClient httpclient = new DefaultHttpClient();
     HttpPost httppost = new HttpPost("http://hotelkaveri.net/getrestaurants.php");
  List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
      
      System.out.println("---------------------userName---------------------------------"+ userName);
      System.out.println("---------------------password---------------------------------"+ password);
     
      nameValuePairs.add(new BasicNameValuePair("UserName", userName));//listOfOrdersToSen.get(i).getTableNo().toString()));           
          nameValuePairs.add(new BasicNameValuePair("Password", password));  
          httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
   // httpclient.execute(httppost);
  HttpResponse response = httpclient.execute(httppost);
  //HttpEntity entity = response.getEntity();
  responsestr=EntityUtils.toString(response.getEntity()).trim();
  //System.out.println(EntityUtils.getContentMimeType(entity));
  System.out.println("------------------responsestr-------------"+responsestr);
} catch (Exception e) {         
    }
 
 

if(responsestr.contains("restname")){
  trimString=responsestr.substring(137, (responsestr.length()- 46)).trim();
  System.out.println("---------------------trimString--------------------------------"+ trimString);
  // XMLParser parser = new XMLParser();
  System.out.println("--------------");

//Here in below "doc" object become Null,here iam getting the value in "trimString" but its unable to parse that string,because that string having '&',so i just replace it .then problem is over. 
In order to solve this problem i just used this line here -->
trimString=trimString.replaceAll("&", "&amp;");  then problem solved..

  Document doc = getDomElement(trimString); // getting DOM element
  System.out.println("-------doc-------"+doc);
  NodeList nl = doc.getElementsByTagName("name");
  SharedVariables.restaurantNameArray=new String[nl.getLength()];
  SharedVariables.restaurantCodeArray=new String[nl.getLength()];
  //preparedTime=new String[nl.getLength()];
  //itemCode=new String[nl.getLength()];
  // looping through all item nodes <item>
  for (int i = 0; i < nl.getLength(); i++) {
  Element e = (Element) nl.item(i);  
 
  SharedVariables.restaurantNameArray[i] = getValue(e, "restname"); // name child value
  System.out.println("-----------------------------------restname------------"+SharedVariables.restaurantNameArray[i]);
  SharedVariables.restaurantCodeArray[i]= getValue(e, "restcode"); // description child value
  System.out.println("-------------------------------------restCode-------"+SharedVariables.restaurantCodeArray[i]);
  //itemRate[i] = getValue(e, "it_rate"); // cost child value
  // System.out.println("-------------------------------------------cost------"+itemRate[i]);
  //preparedTime[i] = getValue(e, "pretime"); // description child value
  // System.out.println("-------------------------------------description-------"+preparedTime[i]);
    
  }
  }


activity.runOnUiThread(new Runnable() {
@Override
public void run() {
 
  /*if(progressDialog.isShowing())
progressDialog.dismiss();*/
SharedVariables.hideActivityIndicator(progressDialog);
loginEmailEdtr.setText("");
loginPasswordEdtr.setText("");

System.out.println("----------responsestr length-----------"+responsestr.trim().length());
System.out.println("----------responsestr length-----------"+trimString.trim().length());
if(trimString!=null)
if(trimString.contains("restname")){
//trimString="";

Intent i=new Intent(PLLoginScreen.this, RestarentSelectActivity.class);
//i.putExtra("restNameArray", restName);
//i.putExtra("restCodeArray", restCode);
//i.putExtra("itemRateArray", itemRate);
//i.putExtra("itemPreparedTime", preparedTime);
startActivity(i);
}else{
SharedVariables.showAlertMessage(" Enter valid Username and Pass", activity);
}
}
  });

//timeoutHandler.sendEmptyMessage(0);



/**/



}});thread.start();
}else
{
SharedVariables.showAlertMessage("No Internet Connection !!", this);
}





Comments

Popular posts from this blog

Custom Dialog with no title and full screen in Android

Best working code to set Date limits on Date Picker Dialog,in Android

code to display .pdf,.text,.DOC,.DOCX,.doc extension files exists in SDCard