Note that there are some explanatory texts on larger screens.

plurals
  1. POFatalException when trying to open alert dialog box for the second time
    primarykey
    data
    text
    <p>here is my code</p> <pre><code>import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.RadioButton; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity implements OnClickListener { RadioButton r1, r2; Button exit, submit, report,settings,about; EditText amount; double Liters = 0; double ppetrol; double pdiesel; double damount; String date, time, dbamt; String price_petrol; String price_diesel; DatabaseHandler db; // XML parsing data types // All static variables static final String URL = "http://pixelexis.host56.com/data.xml"; // XML node keys static final String KEY_ITEM = "item"; // parent node(to check every nodes) static final String PETROL = "petrol"; static final String DIESEL = "diesel"; AlertDialog.Builder alert; TextView input1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); alert = new AlertDialog.Builder(this); input1 = new TextView(this); r1 = (RadioButton)findViewById(R.id.radiopetrol); r2 = (RadioButton)findViewById(R.id.radiodiesel); exit = (Button)findViewById(R.id.exitbutton); submit = (Button)findViewById(R.id.submit); amount = (EditText)findViewById(R.id.amt); report = (Button)findViewById(R.id.repobutton); settings = (Button)findViewById(R.id.setbutton); about = (Button)findViewById(R.id.abtbutton); final DatabaseHandler db = new DatabaseHandler(this); final Calendar c = Calendar.getInstance(); int mYear = c.get(Calendar.YEAR); int mMonth = c.get(Calendar.MONTH); int mDay = c.get(Calendar.DAY_OF_MONTH); int mHour = c.get(Calendar.HOUR_OF_DAY); int mMinute = c.get(Calendar.MINUTE); TextView t = (TextView)findViewById(R.id.time); TextView d = (TextView)findViewById(R.id.date); d.setText(" Date:" + mDay+" / "+mMonth+1 + " / "+mYear+" "); t.setText("Time:" + mHour+" : "+mMinute); date = d.getText().toString(); time = t.getText().toString(); // XML to HashMap ArrayList&lt;HashMap&lt;String, String&gt;&gt; menuItems = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); XMLParser parser = new XMLParser(); String xml = parser.getXmlFromUrl(URL); // getting XML Document doc = parser.getDomElement(xml); // getting DOM element NodeList nl = doc.getElementsByTagName(KEY_ITEM); // looping through all item nodes &lt;item&gt; for (int i = 0; i &lt; nl.getLength(); i++) { // creating new HashMap HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); Element e = (Element) nl.item(i); // adding each child node to HashMap key =&gt; value map.put(PETROL, parser.getValue(e, PETROL)); map.put(DIESEL, parser.getValue(e, DIESEL)); // adding HashList to ArrayList menuItems.add(map); } menuItems.trimToSize(); price_petrol = menuItems.get(0).values().toString(); price_diesel = menuItems.get(1).values().toString(); String regx = ",[] "; char[] ca = regx.toCharArray(); for(char c1 : ca) { price_petrol = price_petrol.replace(""+c1, ""); price_diesel = price_diesel.replace(""+c1, ""); } System.out.println("Price of petrol = " + price_petrol); System.out.println("Price of diesel = " + price_diesel); ppetrol = Double.parseDouble(price_petrol); pdiesel = Double.parseDouble(price_diesel); // int count = db.getValuesCount(); /** * DATABASE OPERATIONS * */ // Inserting values Log.d("Insert: ", "Inserting .."); // db.addValues(new Values(date, time, price_petrol,dbamt )); exit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { System.exit(0); // Force stopping all process and shutting down application } }); about.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "App by Junior Hacker...", Toast.LENGTH_LONG).show(); } }); settings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alert.setTitle("Current fuel price"); alert.setView(input1); input1.setTextColor(Color.parseColor("#FFFFFF")); input1.setText("Petrol : "+price_petrol+ " Diesel : "+price_diesel); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); alert.show(); } }); report.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getApplicationContext(), ListviewActivity.class); startActivity(i); } }); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dbamt = amount.getText().toString(); if(amount.getText().toString() != null &amp;&amp; ! amount.getText().toString().equalsIgnoreCase("")) { if(r1.isChecked()) { damount = Double.parseDouble(amount.getText().toString()); Liters = damount/ppetrol; db.addValues(new Values(date, time, price_petrol,dbamt )); Toast.makeText(getApplicationContext(), "Data Submitted Successfully", Toast.LENGTH_LONG).show(); amount.setText(""); // Reading all values Log.d("Reading: ", "Reading all contacts.."); List&lt;Values&gt; value = db.getAllValues(); for (Values val : value) { String log = "Id: "+val.getID()+" ,Date: " + val.getDate() + " ,Time: " + val.getTime() + ",Price: " + val.getPrice() + ",Amount: " + val.getAmount(); // Writing values to log Log.d("The Log-&gt; ", log); } } else if(r2.isChecked()) { damount = Double.parseDouble(amount.getText().toString()); Liters = damount/pdiesel; Toast.makeText(getApplicationContext(), "Data Submitted Successfully", Toast.LENGTH_LONG).show(); db.addValues(new Values(date, time, price_diesel,dbamt )); // Reading all values Log.d("Reading: ", "Reading all contacts.."); List&lt;Values&gt; value = db.getAllValues(); for (Values val : value) { String log = "Id: "+val.getID()+" ,Date: " + val.getDate() + " ,Time: " + val.getTime() + ",Price: " + val.getPrice() + ",Amount: " + val.getAmount(); // Writing values to log Log.d("The Log-&gt; ", log); } } System.out.println(Liters); } else { Toast.makeText(getApplicationContext(), "Invalid amount!", Toast.LENGTH_LONG).show(); } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } } </code></pre> <p>the dialog appears on the first click, the next click ends with a <code>FatalException</code></p> <p>and here is my logcat</p> <pre><code>01-31 15:57:55.692: D/AndroidRuntime(272): Shutting down VM 01-31 15:57:55.692: W/dalvikvm(272): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 01-31 15:57:55.762: D/dalvikvm(272): GC_FOR_MALLOC freed 2922 objects / 185432 bytes in 61ms 01-31 15:57:55.772: E/AndroidRuntime(272): FATAL EXCEPTION: main 01-31 15:57:55.772: E/AndroidRuntime(272): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 01-31 15:57:55.772: E/AndroidRuntime(272): at android.view.ViewGroup.addViewInner(ViewGroup.java:1970) 01-31 15:57:55.772: E/AndroidRuntime(272): at android.view.ViewGroup.addView(ViewGroup.java:1865) 01-31 15:57:55.772: E/AndroidRuntime(272): at android.view.ViewGroup.addView(ViewGroup.java:1845) 01-31 15:57:55.772: E/AndroidRuntime(272): at com.android.internal.app.AlertController.setupView(AlertController.java:364) 01-31 15:57:55.772: E/AndroidRuntime(272): at com.android.internal.app.AlertController.installContent(AlertController.java:205) 01-31 15:57:55.772: E/AndroidRuntime(272): at android.app.AlertDialog.onCreate(AlertDialog.java:251) 01-31 15:57:55.772: E/AndroidRuntime(272): at android.app.Dialog.dispatchOnCreate(Dialog.java:307) 01-31 15:57:55.772: E/AndroidRuntime(272): at android.app.Dialog.show(Dialog.java:225) 01-31 15:57:55.772: E/AndroidRuntime(272): at android.app.AlertDialog$Builder.show(AlertDialog.java:802) 01-31 15:57:55.772: E/AndroidRuntime(272): at com.aabasoft.fuelcalc.MainActivity$3.onClick(MainActivity.java:195) 01-31 15:57:55.772: E/AndroidRuntime(272): at android.view.View.performClick(View.java:2408) 01-31 15:57:55.772: E/AndroidRuntime(272): at android.view.View$PerformClick.run(View.java:8816) 01-31 15:57:55.772: E/AndroidRuntime(272): at android.os.Handler.handleCallback(Handler.java:587) 01-31 15:57:55.772: E/AndroidRuntime(272): at android.os.Handler.dispatchMessage(Handler.java:92) 01-31 15:57:55.772: E/AndroidRuntime(272): at android.os.Looper.loop(Looper.java:123) 01-31 15:57:55.772: E/AndroidRuntime(272): at android.app.ActivityThread.main(ActivityThread.java:4627) 01-31 15:57:55.772: E/AndroidRuntime(272): at java.lang.reflect.Method.invokeNative(Native Method) 01-31 15:57:55.772: E/AndroidRuntime(272): at java.lang.reflect.Method.invoke(Method.java:521) 01-31 15:57:55.772: E/AndroidRuntime(272): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 01-31 15:57:55.772: E/AndroidRuntime(272): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-31 15:57:55.772: E/AndroidRuntime(272): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>What is the problem here? I have other projects also with the same problem, where I need to accept strings from the user using EditTexts, there also the app stops.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload