Note that there are some explanatory texts on larger screens.

plurals
  1. POTimer not shutting down when back button is pressed. Forceclose error on button press
    text
    copied!<p>OK all you super java/android guru's. I know your going to look at this and laugh, but I really need the help. Am a super newbie and have read every Google development doc (and many more) and just can't grasp the concept. Can learn a LOT more by seeing working code rather than a referral to something I already read and obviously didn't understand, so if someone can help me out, that would be wonderful.</p> <p><strong>Main Activity</strong></p> <pre><code> import java.util.Timer; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.webkit.WebView; public class Quotes extends Activity implements OnClickListener { ProgressDialog dialog; private WebView webview; private Timer timer; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); WebView adsview = (WebView) findViewById(R.id.ads); adsview.getSettings().setJavaScriptEnabled(true); adsview.loadUrl("http://www.dgdevelco.com/quotes/androidad.html"); SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); String q = SP.getString("appViewType","http://www.dgdevelco.com/quotes/quotesandroidtxt.html"); String c = SP.getString("appRefreshRate","20"); webview = (WebView) findViewById(R.id.scroll); webview.getSettings().setJavaScriptEnabled(true); webview.setWebViewClient(new QuotesWebView(this)); webview.loadUrl(q); ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor(); timer.scheduleAtFixedRate(new Runnable() { @Override public void run() { webview.reload(); } }, 10, Long.parseLong(c),TimeUnit.SECONDS); findViewById(R.id.refresh).setOnClickListener(this); } @Override public void onPause(){ timer.cancel(); super.onPause(); } @Override public void onResume(){ webview.reload(); super.onResume(); } public void onClick(View v){ switch(v.getId()){ case R.id.refresh: webview.reload(); break; } } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); MenuItem about = menu.getItem(0); about.setIntent(new Intent(this, About.class)); MenuItem preferences = menu.getItem(1); preferences.setIntent(new Intent(this, Preferences.class)); return true; } } </code></pre> <p><strong>CatLog</strong></p> <pre><code> 07-05 17:28:51.001: DEBUG/AndroidRuntime(11446): Shutting down VM 07-05 17:28:51.001: WARN/dalvikvm(11446): threadid=1: thread exiting with uncaught exception (group=0x40018560) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): FATAL EXCEPTION: main 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): java.lang.RuntimeException: Unable to pause activity {com.dge.quotes/com.dge.quotes.Quotes}: java.lang.NullPointerException 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2477) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2424) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2404) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at android.app.ActivityThread.access$1700(ActivityThread.java:124) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:979) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at android.os.Handler.dispatchMessage(Handler.java:99) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at android.os.Looper.loop(Looper.java:123) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at android.app.ActivityThread.main(ActivityThread.java:3806) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at java.lang.reflect.Method.invokeNative(Native Method) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at java.lang.reflect.Method.invoke(Method.java:507) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at dalvik.system.NativeStart.main(Native Method) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): Caused by: java.lang.NullPointerException 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at com.dge.quotes.Quotes.onPause(Quotes.java:72) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at android.app.Activity.performPause(Activity.java:3901) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1191) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2459) 07-05 17:28:51.017: ERROR/AndroidRuntime(11446): ... 12 more 07-05 17:28:51.509: WARN/ActivityManager(1319): Activity pause timeout for HistoryRecord{40ba7e20 com.dge.quotes/.Quotes} </code></pre> <p>Any and all help would be greatly appreciated.</p> <p>At this point I feel like a completely crazed woman who really needs to get this project done so my life can move forward. If anyone (ANYONE) has an answer to this, I would REALLY Appreciate it.</p>
 

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