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 8296781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:09:02+00:00 2026-06-08T15:09:02+00:00

So I have a spinner that needs to populate a WebView using an HTML

  • 0

So I have a spinner that needs to populate a WebView using an HTML file located in the assets folder. I have my code that looks descent but obviously doesn’t work. I will attach the Java and the error.

I know I’m making mistakes here and need to learn what I am doing wrong.

public class atcSectionWeb extends Activity {

public static final int DIALOG_DOWNLOAD_PROGRESS = 0;
private ProgressDialog mProgressDialog;

Spinner spLoadFrom;
private ArrayAdapter<CharSequence> spinnerArrayAdapter;

String name[] = { "1.html", "2.html", "3.html", "etc.html" };
String displayName[] = {"1st Name", "2nd Name", "3rd name", "And So On" };

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.atcsectionweb);

    mProgressDialog = new ProgressDialog(atcSectionWeb.this);
    mProgressDialog.setIndeterminate(false);
    mProgressDialog.setMax(100);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

    spLoadFrom = (Spinner) findViewById(R.id.Spinner02);

    spinnerArrayAdapter = new ArrayAdapter<CharSequence>(this,
            android.R.layout.simple_spinner_item, displayName);
    spinnerArrayAdapter
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spLoadFrom.setAdapter(spinnerArrayAdapter);

    SpinnerListener spListener = new SpinnerListener();
    spLoadFrom.setOnItemSelectedListener(spListener);


    Button atcBack = (Button) findViewById(R.id.atcBacksecweb);
    atcBack.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            setResult(RESULT_OK);
            finish();
        }
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu2, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.atcAbout2:
        Intent atcAboutWeb = new Intent(atcSectionWeb.this,
                atcAboutWeb.class);
        startActivity(atcAboutWeb);
        break;
    case R.id.atcContact2:
        emailme();
        break;
    }
    return true;
}

private void emailme() {
    // TODO Auto-generated method stub
    try{
    String domsEmail = "";
    String message = "Insert Message Here";
    String myemail[] = { domsEmail };
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, myemail);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
    emailIntent.setType("plain/text");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
    startActivity(emailIntent);
    }catch (Exception  e) {
        Toast.makeText(
                atcSectionWeb.this,
                "No email application is available, please download one from Play store.",
                Toast.LENGTH_LONG).show();

    }
}

public class SpinnerListener implements OnItemSelectedListener {
    public SpinnerListener() {
    }

    public void onItemSelected(AdapterView<?> arg0, View arg1,
            final int position, long arg2) {

        Button atcSection = (Button) findViewById(R.id.atcSubmitweb);
        atcSection.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

                WebView wv = (WebView)findViewById(R.id.ctiWebView);
                wv.setWebViewClient(new WebViewClient() {  
                      @Override  
                      public boolean shouldOverrideUrlLoading(WebView view, String url)  
                      {  
                        view.loadUrl(url);
                        return true;
                      }  
                    });         
                wv.loadUrl("file:///android_asset/" + position); 




            }
        });

    }

    public void onNothingSelected(AdapterView<?> arg0) {

    }
}
}

LogCat:

07-28 23:40:09.438: E/AndroidRuntime(584): FATAL EXCEPTION: main
07-28 23:40:09.438: E/AndroidRuntime(584): java.lang.NullPointerException
07-28 23:40:09.438: E/AndroidRuntime(584):  at com.assistant.atcSectionWeb$SpinnerListener$1.onClick(atcSectionWeb.java:240)
07-28 23:40:09.438: E/AndroidRuntime(584):  at android.view.View.performClick(View.java:2485)
07-28 23:40:09.438: E/AndroidRuntime(584):  at android.view.View$PerformClick.run(View.java:9080)
07-28 23:40:09.438: E/AndroidRuntime(584):  at android.os.Handler.handleCallback(Handler.java:587)
07-28 23:40:09.438: E/AndroidRuntime(584):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-28 23:40:09.438: E/AndroidRuntime(584):  at android.os.Looper.loop(Looper.java:123)
07-28 23:40:09.438: E/AndroidRuntime(584):  at android.app.ActivityThread.main(ActivityThread.java:3683)
07-28 23:40:09.438: E/AndroidRuntime(584):  at java.lang.reflect.Method.invokeNative(Native Method)
07-28 23:40:09.438: E/AndroidRuntime(584):  at java.lang.reflect.Method.invoke(Method.java:507)
07-28 23:40:09.438: E/AndroidRuntime(584):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-28 23:40:09.438: E/AndroidRuntime(584):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-28 23:40:09.438: E/AndroidRuntime(584):  at dalvik.system.NativeStart.main(Native Method)

Error after copying SALMAN’s code:

07-29 01:04:58.290: E/AndroidRuntime(532): FATAL EXCEPTION: main
07-29 01:04:58.290: E/AndroidRuntime(532): java.lang.NullPointerException
07-29 01:04:58.290: E/AndroidRuntime(532):  at com.assistant.atcSectionWeb$SpinnerListener.onItemSelected(atcSectionWeb.java:236)
07-29 01:04:58.290: E/AndroidRuntime(532):  at android.widget.AdapterView.fireOnSelected(AdapterView.java:871)
07-29 01:04:58.290: E/AndroidRuntime(532):  at android.widget.AdapterView.access$200(AdapterView.java:42)
07-29 01:04:58.290: E/AndroidRuntime(532):  at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:837)
07-29 01:04:58.290: E/AndroidRuntime(532):  at android.os.Handler.handleCallback(Handler.java:587)
07-29 01:04:58.290: E/AndroidRuntime(532):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-29 01:04:58.290: E/AndroidRuntime(532):  at android.os.Looper.loop(Looper.java:123)
07-29 01:04:58.290: E/AndroidRuntime(532):  at android.app.ActivityThread.main(ActivityThread.java:3683)
07-29 01:04:58.290: E/AndroidRuntime(532):  at java.lang.reflect.Method.invokeNative(Native Method)
07-29 01:04:58.290: E/AndroidRuntime(532):  at java.lang.reflect.Method.invoke(Method.java:507)
07-29 01:04:58.290: E/AndroidRuntime(532):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-29 01:04:58.290: E/AndroidRuntime(532):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-29 01:04:58.290: E/AndroidRuntime(532):  at dalvik.system.NativeStart.main(Native Method)
  • 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-08T15:09:07+00:00Added an answer on June 8, 2026 at 3:09 pm

    Pasting the whole code of an application just made this for your purpose.

     package asdasd.adasd.ad;
    
    
    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuInflater;
    import android.view.MenuItem;
    import android.view.View;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemSelectedListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.Spinner;
    import android.widget.Toast;
    
    public class AsdasdasActivity extends Activity {
    
    public static final int DIALOG_DOWNLOAD_PROGRESS = 0;
    private ProgressDialog mProgressDialog;
    
    Spinner spLoadFrom;
    private ArrayAdapter<CharSequence> spinnerArrayAdapter;
    
    String name[] = { "1.html", "2.html", "3.html"};
    String displayName[] = {"1st Name", "2nd Name", "3rd name" };
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        mProgressDialog = new ProgressDialog(AsdasdasActivity.this);
        mProgressDialog.setIndeterminate(false);
        mProgressDialog.setMax(100);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    
        spLoadFrom = (Spinner) findViewById(R.id.Spinner02);
    
        spinnerArrayAdapter = new ArrayAdapter<CharSequence>(this,
                android.R.layout.simple_spinner_item, displayName);
        spinnerArrayAdapter
                .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spLoadFrom.setAdapter(spinnerArrayAdapter);
    
        SpinnerListener spListener = new SpinnerListener();
        spLoadFrom.setOnItemSelectedListener(spListener);
    
    
        WebView wv = (WebView)findViewById(R.id.webView1);
    
        wv.getSettings().setJavaScriptEnabled(true);
     /*   wv.setWebViewClient(new WebViewClient() {  
              @Override  
              public boolean shouldOverrideUrlLoading(WebView view, String url)  
              {  
                view.loadUrl(url);
                return true;
              }  
            });    
            */     
        wv.loadUrl("file:///android_asset/htmlfileMine.html"); 
    
    
        Button atcBack = (Button) findViewById(R.id.atcBacksecweb);
        atcBack.setOnClickListener(new View.OnClickListener() {
    
            public void onClick(View v) {
                // TODO Auto-generated method stub
                setResult(RESULT_OK);
                finish();
            }
        });
    
    }
    
    
    
    private void emailme() {
        // TODO Auto-generated method stub
        try{
        String domsEmail = "";
        String message = "Insert Message Here";
        String myemail[] = { domsEmail };
        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, myemail);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
        startActivity(emailIntent);
        }catch (Exception  e) {
            Toast.makeText(
                    AsdasdasActivity.this,
                    "No email application is available, please download one from Play store.",
                    Toast.LENGTH_LONG).show();
    
        }
    }
    
    public class SpinnerListener implements OnItemSelectedListener {
        public SpinnerListener() {
        }
    
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                final int position, long arg2) {
    
    
                    WebView wv = (WebView)findViewById(R.id.webView1);
    
                    wv.getSettings().setJavaScriptEnabled(true);
                   wv.setWebViewClient(new WebViewClient() {  
                          @Override  
                          public boolean shouldOverrideUrlLoading(WebView view, String url)  
                          {  
                            view.loadUrl(url);
                            return true;
                          }  
                        });    
    
                    wv.loadUrl("file:///android_asset/"+name[position]); 
    
    
    
    
    
    
        }
    
        public void onNothingSelected(AdapterView<?> arg0) {
    
        }
    }
    }
    

    /// XML LAYOUT

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    
        <Spinner
            android:id="@+id/Spinner02"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
        <ProgressBar
            android:id="@+id/progressBar1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
        <Button
            android:id="@+id/atcSubmitweb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    
        <Button
            android:id="@+id/atcBacksecweb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    
        <WebView
            android:id="@+id/webView1"
            android:layout_width="300dp"
            android:layout_height="300dp" />
    
    </LinearLayout>
    

    Thanks.

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

Sidebar

Related Questions

I have an android spinner that's populated by a list of strings using an
I have a file called 'LoginViewController' that needs to do an action from the
I have within a TabActivity a Spinner that will be generated dynamically. Just to
I have one spinner, and I am populating that. I have list of values
Hi I have a spinner (spinner5) and whenever the user selects an item that
I have a simple function that shows loading spinner while fetching data (usually takes
I have a spinner and I am trying to populate it manually in the
I'm using the ActionBar. I'd like to have a refresh progress spinner on the
I have a AS spinner class that I downloaded from Jake Hawkes ( click
I have an application, which has a Spinner that I want populated with some

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.