Note that there are some explanatory texts on larger screens.

plurals
  1. POCatch statements not working in android
    primarykey
    data
    text
    <p>I am working with an android database oriented program. This activity is from one of my tab. When i press that particular tab it will get the value from the db and if any null values from the db it will catch it and show an alertbox and changing to another tab. This is my logic. But it is not executing the catch block. It is going straight to the webview and showing there a null value. Please anyone help me to fix this error.Here is my class...</p> <p><strong>LocationActivity</strong> </p> <pre><code>import java.util.List; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.Window; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.widget.ProgressBar; @SuppressLint("SetJavaScriptEnabled") public class LocationActivity extends Activity { MainTabActivity mainTab; WebView mWebView; GPSTracker g; double my_lat, my_lon; String lat, lon, to_lat, to_lon, addressText, temp_lat, temp_lon; DatabaseHandler db; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); db = new DatabaseHandler(this); g = new GPSTracker(this); Log.d("Reading: ", "Location Activity Reading all Values"); List&lt;Datas&gt; datas = db.getAllDatas(); for (Datas dat : datas) { try{ to_lat = dat.getlat(); to_lon = dat.getlon(); }catch(NullPointerException e){ AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Oops!"); // set dialog message alert .setMessage("Please select a destination before finding your route!") .setCancelable(false) .setPositiveButton("ok",new DialogInterface.OnClickListener() { @SuppressWarnings("deprecation") public void onClick(DialogInterface dialog,int id) { ((MainTabActivity)getParent()).getTabHost().setCurrentTab(0); } }); // create alert dialog AlertDialog alertDialog = alert.create(); // show it alertDialog.show(); Log.d(to_lat, to_lon); System.out.println("Frim thap thee "+ to_lat + " " + to_lon); } } setContentView(R.layout.webview); getWindow().setFeatureInt(Window.FEATURE_PROGRESS,Window.PROGRESS_VISIBILITY_ON); final ProgressBar pb = (ProgressBar) findViewById(R.id.progressBar1); pb.setVisibility(View.VISIBLE); my_lat = g.getLatitude(); my_lon = g.getLongitude(); lat = String.valueOf(my_lat); lon = String.valueOf(my_lon); mWebView = (WebView)findViewById(R.id.webview1); mWebView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { pb.setProgress(progress); if (progress == 100) { pb.setVisibility(View.GONE); } } }); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); mWebView.setWebViewClient(new HelloWebViewClient()); addressText = lat + "," + lon + "+to:" + to_lat + ","+ to_lon; addressText = addressText.replaceAll(" ", "%20"); addressText = addressText.replaceAll("#", "%23"); mWebView.loadUrl("http://maps.google.com/maps?q=from:"+ addressText); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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