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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:20:08+00:00 2026-05-25T17:20:08+00:00

I am working in android, i want to make a scrollview. this is my

  • 0

I am working in android, i want to make a scrollview.
this is my code for that :

package com.pericent;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TextView;

public class HelloTabWidget extends Activity  {

    private String TAG="HelloTabWidget";



    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Log.v(TAG,"i am just before everything");
        HorizontalScrollView hr=new HorizontalScrollView(this);
        hr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
        LinearLayout layout=new LinearLayout(this);
        LinearLayout mainlayout=new LinearLayout(this);
        mainlayout=(LinearLayout)findViewById(R.id.upper1);
        layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        Log.v(TAG,"i am just after the declarations");
        for(int i=0;i<100;i++){
            TextView txt=new TextView(this);
            txt.setText("Text " + i );
            layout.addView(txt);
        }
        Log.v(TAG,"i am after the for loop");
        hr.addView(layout);

        mainlayout.addView(hr);//<<---this is creating NullPointerException
        setContentView(R.layout.cecking);
        Log.v(TAG,"i am after the everything");

  }
}

and this my cecking.xml

<?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:id="@+id/upper1">

</LinearLayout>

whenever i run the program, this error is occurred:-

Unable to start activity ComponentInfo{com.pericent/com.pericent.HelloTabWidget}: java.lang.NullPointerException

and in this line the error is occurred:- mainlayout.addView(hr);

please help me to find out the reason of error.
Thank you in advance.

  • 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-25T17:20:08+00:00Added an answer on May 25, 2026 at 5:20 pm

    You are not setting any layout for the Activity
    as well as you are not Inflating checking.xml for that Activity.
    That’s why mainlayout cannot be found and cause NullPointerException
    Try this way:
    checking.xml

    <?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">
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
            android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/upper1">
            </LinearLayout>
    </LinearLayout>
    

    and then set your layout inside onCreate() of the Activity
    like this:

    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            this.setContenView(R.layout.checking);
            mainlayout=(LinearLayout)findViewById(R.id.upper1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working in android . I want to make sharedpreference in my code,
i am working in android. I want to make TabHost and Tab widget. this
I'm trying to make an Android app, and the feature that I'm working on
I am working on an Android app that utilizes the Google Maps API MapView,
I'm working on a relatively simple Android app. I want it to have an
Here i make 5 Tab buttons that are working proper but now i want
I have some code which is working in iphone and i want to make
I am working on Android app and as part of that, I have to
I just started working on a new Eclipse Android project and want to make
I want to make a http request with android. is use this: void testHTTP()

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.