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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:43:48+00:00 2026-06-02T10:43:48+00:00

I have NewTransferActivity class, which extends TabActivity. The code: public class NewTransferActivity extends TabActivity

  • 0

I have NewTransferActivity class, which extends TabActivity. The code:

public class NewTransferActivity extends TabActivity {

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

    TabHost tabHost = getTabHost();
    TabHost.TabSpec spec;

    spec = tabHost.newTabSpec("receiver").setIndicator("Rec").setContent(getReceiverTab());
    tabHost.addTab(spec);

    spec = tabHost.newTabSpec("transfer").setIndicator("Trans").setContent(getTransferTab());
    tabHost.addTab(spec);

}

private TabContentFactory getReceiverTab(){
    TabContentFactory factory = new TabContentFactory() {
        @Override
        public View createTabContent(String tag) {

            ...

            return layout;
        }
    };
    return factory;
}

private TabContentFactory getTransferTab(){
    TabContentFactory factory = new TabContentFactory() {

        @Override
        public View createTabContent(String tag) {
            LinearLayout layout = (LinearLayout) findViewById(R.id.mytrans);

            if (layout == null){
                //layout = new LinearLayout(NewTransferActivity.this);
                System.out.println("NULL>>>>>>");
                return new LinearLayout(NewTransferActivity.this);
            }
            return layout;
        }
    };
    return factory;
} ...

my xml file, which contains layout is:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mytrans"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >


<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <requestFocus />
</EditText>


<TextView
    android:id="@+id/textView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/editText2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />


<TextView
    android:id="@+id/textView3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/editText3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />


<TextView
    android:id="@+id/textView4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/editText4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

I want to load layout for a single tab from xml file which I definded. Unfortunatelly I am getting NullPointerException because layout is null in method getTransferTab(). ‘LinearLayout layout = (LinearLayout) findViewById(R.id.mytrans)’ returns null. What I am doing wrong? Thanks 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-06-02T10:43:49+00:00Added an answer on June 2, 2026 at 10:43 am

    You should rather try to use LayoutInflater to get the view hierarchy from the xml,

        TabContentFactory factory = new TabContentFactory() {
            @Override
            public View createTabContent(String tag) {
    
                 LayoutInflater inflater = LayoutInflater.from(Activity_Name.this);
                 View linearLayout = inflater.inflate(R.layout.mytrans, null);
    
                return linearLayout;
            }
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
Have you ever obfuscated your code before? Are there ever legitimate reasons to do
Have you ever created or encountered a self modifying code in Java? If yes,
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
Have added the following code to my SQL query: (Note cut down version) DECLARE
Have some code: using (var ctx = new testDataContext()) { var options = new
Have a look at the following code to find X^y. /* Find exponent in
Have a group of related projects running in SQL Server 2005 for which I
Have following kernel function: private static String programSource = __kernel void sampleKernel(__global float *Y,
Have piece of code like below: var workStream = new MemoryStream(); var doc =

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.