Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8403931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:27:54+00:00 2026-06-09T22:27:54+00:00

My title is pretty self explanatory. Here’s my code: public class MainActivity extends Activity

  • 0

My title is pretty self explanatory. Here’s my code:

 public class MainActivity extends Activity {

    private WebView browse;
    private TextView t;
    private String address="http://www.google.com";
    private int refresh, clearcache, time, refreshTime, cacheTime;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SharedPreferences gPrefs = PreferenceManager
                .getDefaultSharedPreferences(getBaseContext());
        address = gPrefs.getString("Address", "http://www.google.com");
        refresh = gPrefs.getInt("Refresh", 1);
        clearcache = gPrefs.getInt("ClearCache", 1);
        time = gPrefs.getInt("Time", 0);

        switch (time) {
        case 0:
            refreshTime = refresh * 60 * 60 * 1000;
            break;
        case 1:
            refreshTime = refresh * 60 * 1000;
            break;
        case 2:
            refreshTime = refresh * 1000;
            break;
        }

        switch (time) {
        case 0:
            cacheTime = clearcache * 60 * 60 * 1000;
            break;
        case 1:
            cacheTime = clearcache * 60 * 1000;
            break;
        case 2:
            cacheTime = clearcache * 1000;
            break;
        }

        browse = (WebView) findViewById(R.id.webView1);
        t = (TextView) findViewById(R.id.t);

        browse.getSettings().setJavaScriptEnabled(true);
        browse.getSettings().setPluginsEnabled(true);
        browse.getSettings().setLoadWithOverviewMode(true);
        browse.getSettings().setUseWideViewPort(true);
        browse.getSettings().setBuiltInZoomControls(true);
        browse.getSettings().setSupportZoom(true);
        browse.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        browse.setScrollbarFadingEnabled(true);
        browse.getSettings().setLoadsImagesAutomatically(true);
        browse.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        browse.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);

        browse.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                // TODO Auto-generated method stub
                super.onPageStarted(view, url, favicon);
                t.setVisibility(TextView.VISIBLE);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                // do your stuff here
                super.onPageFinished(view, url);
                t.setVisibility(TextView.GONE);
            }
        });

        try {
            browse.loadUrl(address);
        } catch (Exception e) {
            e.printStackTrace();
        }

        refreshRRryan();
        cacheRRryan();
    }

    final Handler refreshhandler = new Handler();
    final Timer refreshtimer = new Timer();
    final Runnable refreshdoA = new Runnable() {
        @Override
        public void run() {
            browse.reload();
        }
    };

    public void refreshRRryan() {
        TimerTask refreshtask = new TimerTask() {
            @Override
            public void run() {
                refreshhandler.post(refreshdoA);
            }
        };
        refreshtimer.scheduleAtFixedRate(refreshtask, refreshTime, refreshTime);
    }

    final Handler cachehandler = new Handler();
    final Timer cachetimer = new Timer();
    final Runnable cachedoA = new Runnable() {
        @Override
        public void run() {
            browse.clearCache(true);
            getApplicationContext().deleteDatabase("webview.db");
            getApplicationContext().deleteDatabase("webviewCache.db");
        }
    };

    public void cacheRRryan() {
        TimerTask cachetask = new TimerTask() {
            @Override
            public void run() {
                cachehandler.post(cachedoA);
            }
        };
        cachetimer.scheduleAtFixedRate(cachetask, cacheTime, cacheTime);
    }

    @Override
    public File getCacheDir() {
        // NOTE: this method is used in Android 2.1

        return getApplicationContext().getCacheDir();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub
        super.onCreateOptionsMenu(menu);
        MenuInflater blowUp = getMenuInflater();
        blowUp.inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
        case R.id.aboutUs:
            Intent i = new Intent("ABOUT");
            startActivity(i);
            break;
        case R.id.preferences:
            Intent p = new Intent("PREFS");
            startActivityForResult(p, 101);
            break;
        }
        return false;
    }

}

And here’s logcat:

08-17 11:08:05.997: E/AndroidRuntime(1197): FATAL EXCEPTION: main
08-17 11:08:05.997: E/AndroidRuntime(1197): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fit.world.browser/com.fit.world.browser.MainActivity}: java.lang.ClassCastException: java.lang.String
08-17 11:08:05.997: E/AndroidRuntime(1197):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-17 11:08:05.997: E/AndroidRuntime(1197):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-17 11:08:05.997: E/AndroidRuntime(1197):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-17 11:08:05.997: E/AndroidRuntime(1197):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-17 11:08:05.997: E/AndroidRuntime(1197):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 11:08:05.997: E/AndroidRuntime(1197):     at android.os.Looper.loop(Looper.java:123)
08-17 11:08:05.997: E/AndroidRuntime(1197):     at android.app.ActivityThread.main(ActivityThread.java:3683)
08-17 11:08:05.997: E/AndroidRuntime(1197):     at java.lang.reflect.Method.invokeNative(Native Method)
08-17 11:08:05.997: E/AndroidRuntime(1197):     at java.lang.reflect.Method.invoke(Method.java:507)
08-17 11:08:05.997: E/AndroidRuntime(1197):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-17 11:08:05.997: E/AndroidRuntime(1197):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-17 11:08:05.997: E/AndroidRuntime(1197):     at dalvik.system.NativeStart.main(Native Method)
08-17 11:08:05.997: E/AndroidRuntime(1197): Caused by: java.lang.ClassCastException: java.lang.String
08-17 11:08:05.997: E/AndroidRuntime(1197):     at android.app.ContextImpl$SharedPreferencesImpl.getInt(ContextImpl.java:2817)
08-17 11:08:05.997: E/AndroidRuntime(1197):     at com.fit.world.browser.MainActivity.onCreate(MainActivity.java:37)
08-17 11:08:05.997: E/AndroidRuntime(1197):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-17 11:08:05.997: E/AndroidRuntime(1197):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-17 11:08:05.997: E/AndroidRuntime(1197):     ... 11 more

And I’m pretty sure my manifest is fine because the activity runs the first time.

Help me please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:27:55+00:00Added an answer on June 9, 2026 at 10:27 pm
    refresh = gPrefs.getInt("Refresh", 1);
    clearcache = gPrefs.getInt("ClearCache", 1);
    time = gPrefs.getInt("Time", 0);
    

    The first time the app run, it uses the default value you use (1,1,0) above.

    But the second time, it certainly uses the data you’ve saved from a user input perhaps.

    You must be saving it as a string and trying to retrieve it as an int…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The title is pretty much self-explanatory, I'm killing myself over this simplicity. Looked here
The title is pretty self-explanatory, but here's a simplified example: #include <cstdio> template <typename
The title is pretty self explanatory. the following code...: URL imageUrl = new URL(url);
The title is pretty self explanatory. Here's the function I've written for this purpose:
The title is pretty self explanatory, but basically I need the table row to
The title is pretty self-explanatory. When I run my app on Netbeans (Tomcat 7),
The title is pretty self-explanatory: does anyone know of a (good) properties file reader
Title is pretty self-explanatory. I've got a DataGrid for a Windows Form Application, and
The title of this question should be pretty self explanatory. I am making an
The title is pretty self explanatory. I am currently trying to make a cocos2d

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.