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

  • Home
  • SEARCH
  • 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 3979350
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:09:33+00:00 2026-05-20T05:09:33+00:00

I have some confusion regarding where you put regular java code in an android

  • 0

I have some confusion regarding where you put regular java code in an android application.

I’m using the Eclipse SDK and by default when you create an application it makes a .java file with an OnCreate() method. Is this where I would put my code, inside this method?

Right now in my layout I have an imageButton, once this button is clicked I want to open a new WebView page that gets it’s HTML code from the index.html file found in the assets folder. This is what I have so far…

    Button button = (Button)findViewById(R.id.imagebutton1);
    if(button.isPressed())
    {
        WebView webview = new WebView(null);
        setContentView(webview);
        try {
            InputStream fin = getAssets().open("index.html");
                byte[] buffer = new byte[fin.available()];
                fin.read(buffer);
                fin.close();
                webview.loadData(new String(buffer), "text/html", "UTF-8");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

I have this block of code at the end of the onCreate() method right under the line:

setContentView(R.layout.main);

However, once I run the program it crashes and tells me that it failed to start. I’m assuming that it has to do with the fact that the code is in the onCreate. I know that its not where I’m supposed to put it, but I can’t think of anywhere else the code should go. Am I supposed to make a new .java file and have a main method there? I’m currently taking classes for C++ and C# so this android thing is still new to me.

  • 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-05-20T05:09:34+00:00Added an answer on May 20, 2026 at 5:09 am

    Have you done the tutorials? If not I would start there to learn about the basics of creating and working with an Android Activity. Once you have worked your way through them, read the application fundamentals to understand the lifecycle more fully.

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

Sidebar

Related Questions

I have some confusion related to the .NET platform build options in Visual Studio
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
I have some C# / asp.net code I inherited which has a textbox which
I have some code like this in a winforms app I was writing to
I have some kind of test data and want to create a unit test
I have some confusion about when to use the self keyword during ivars assignment,
I have some confusion with reference type following is the test example please tell
EDIT: My example might have created some confusion. I have changed the example below
I have some code which needs to do things based on a schedule: e.g.
I have some code that acquires a value for an enum: StringUtils.isEmpty(getEnumMember().value()); The supporting

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.