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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:58:01+00:00 2026-06-04T13:58:01+00:00

I keep getting this error on running but no compile errors? here is the

  • 0

I keep getting this error on running but no compile errors? here is the logcat and code for main.

05-25 12:29:25.543: W/dalvikvm(384): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-25 12:29:25.582: E/AndroidRuntime(384): FATAL EXCEPTION: main
05-25 12:29:25.582: E/AndroidRuntime(384): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.tablayout/com.example.tablayout.TablayoutActivity}: java.lang.NullPointerException
05-25 12:29:25.582: E/AndroidRuntime(384):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
05-25 12:29:25.582: E/AndroidRuntime(384):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-25 12:29:25.582: E/AndroidRuntime(384):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-25 12:29:25.582: E/AndroidRuntime(384):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-25 12:29:25.582: E/AndroidRuntime(384):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-25 12:29:25.582: E/AndroidRuntime(384):  at android.os.Looper.loop(Looper.java:123)
05-25 12:29:25.582: E/AndroidRuntime(384):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-25 12:29:25.582: E/AndroidRuntime(384):  at java.lang.reflect.Method.invokeNative(Native Method)
05-25 12:29:25.582: E/AndroidRuntime(384):  at java.lang.reflect.Method.invoke(Method.java:521)
05-25 12:29:25.582: E/AndroidRuntime(384):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-25 12:29:25.582: E/AndroidRuntime(384):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-25 12:29:25.582: E/AndroidRuntime(384):  at dalvik.system.NativeStart.main(Native Method)
05-25 12:29:25.582: E/AndroidRuntime(384): Caused by: java.lang.NullPointerException
05-25 12:29:25.582: E/AndroidRuntime(384):  at android.app.Activity.setContentView(Activity.java:1647)
05-25 12:29:25.582: E/AndroidRuntime(384):  at android.app.TabActivity.ensureTabHost(TabActivity.java:114)
05-25 12:29:25.582: E/AndroidRuntime(384):  at android.app.TabActivity.getTabHost(TabActivity.java:136)
05-25 12:29:25.582: E/AndroidRuntime(384):  at com.example.tablayout.TablayoutActivity.<init>(TablayoutActivity.java:15)
05-25 12:29:25.582: E/AndroidRuntime(384):  at java.lang.Class.newInstanceImpl(Native Method)
05-25 12:29:25.582: E/AndroidRuntime(384):  at java.lang.Class.newInstance(Class.java:1429)
05-25 12:29:25.582: E/AndroidRuntime(384):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-25 12:29:25.582: E/AndroidRuntime(384):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
05-25 12:29:25.582: E/AndroidRuntime(384):  ... 11 more






    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@android:id/tabhost" 
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
     <LinearLayout android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"
      android:baselineAligned="false">
    <FrameLayout android:layout_width="0dip" 
        android:layout_height="fill_parent" 
        android:layout_weight="0.2">
    <TabWidget android:id="@android:id/tabs" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:visibility="invisible"/>
        <LinearLayout android:layout_width="fill_parent"  
            android:layout_height="fill_parent"
            android:orientation="vertical">
            <Button android:layout_height="0dip" 
                android:layout_width="fill_parent" 
                android:layout_weight="1.0"
            android:background="@drawable/icon_photos_tab"               
                android:id="@+id/artist_id" 
                android:onClick="tabHandler"/>
            <Button android:layout_height="0dip" 
                android:layout_width="fill_parent" 
                android:layout_weight="1.0"
            android:background="@drawable/icon_videos_tab"  
                android:id="@+id/album_id" 
                android:onClick="tabHandler"/>
            <Button android:layout_height="0dip" 
                android:layout_width="fill_parent" 
                android:layout_weight="1.0"
            android:background="@drawable/icon_songs_tab"   
                android:id="@+id/song_id" 
                android:onClick="tabHandler"/>
    </LinearLayout> 
    </FrameLayout>       
    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:layout_weight="0.8"/>
    </LinearLayout>
    </TabHost>

here is the main.java file, this way you can see how it was a global variable and where i removed it from. Also added the buttons globally instead of locally to that one spot.

    import android.app.TabActivity;
    import android.content.Intent;
   import android.os.Bundle;
   import android.view.View;
   import android.widget.Button;
   import android.widget.TabHost;
   import android.widget.TabHost.TabSpec;

   public class TablayoutActivity extends TabActivity {
    /** Called when the activity is first created. */

Button artistButton, songButton, videosButton;
TabHost tabHost = getTabHost();

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

    //TabHost tabHost = getTabHost();

    // Tab for Photos
    TabSpec photospec = tabHost.newTabSpec("Photos");
    // setting Title and Icon for the Tab
    photospec.setIndicator("Photos",   getResources().getDrawable(R.drawable.icon_photos_tab));
    Intent photosIntent = new Intent(this, PhotosActivity.class);
    photospec.setContent(photosIntent);

    // Tab for Songs
    TabSpec songspec = tabHost.newTabSpec("Songs");
    songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.icon_songs_tab));
    Intent songsIntent = new Intent(this, SongsActivity.class);
    songspec.setContent(songsIntent);

    // Tab for Videos
    TabSpec videospec = tabHost.newTabSpec("Videos");
    videospec.setIndicator("Videos",         getResources().getDrawable(R.drawable.icon_videos_tab));
    Intent videosIntent = new Intent(this, VideosActivity.class);
    videospec.setContent(videosIntent);

    // Adding all TabSpec to TabHost
    tabHost.addTab(photospec); // Adding photos tab
    tabHost.addTab(songspec); // Adding songs tab
    tabHost.addTab(videospec); // Adding videos tab




   }

    public void tabHandler(View target){
    artistButton.setSelected(false);
    videosButton.setSelected(false);
    songButton.setSelected(false);
    if(target.getId() == R.id.artist_id){
        tabHost.setCurrentTab(0);
        artistButton.setSelected(true);
    } else if(target.getId() == R.id.album_id){
        tabHost.setCurrentTab(1);
        videosButton.setSelected(true);
    } else if(target.getId() == R.id.song_id){
        tabHost.setCurrentTab(2);
        songButton.setSelected(true);
    }
   };

    }
  • 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-04T13:58:03+00:00Added an answer on June 4, 2026 at 1:58 pm

    You are probably trying to call getTabHost() somewhere in your constructor or in setting a field on your class. You have to call it from within onCreate() since getTabHost() down deep tries to get the current window, which isn’t created yet at constructor time.

    Any time after onCreate() has been called will be fine.

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

Sidebar

Related Questions

I keep getting this error while trying to modify some tables. Here's my code:
So I keep getting this error when trying to compile C++ code using CodeBlocks.
I keep getting this error System.Web.HttpException was unhandled by user code Message=Validation of viewstate
I keep getting this error whenever I call gethostbyname() in my C code. ==7983==
I keep getting this error after my application is running for 2 days. I've
Hi i'm trying to run Nant but keep getting this error when i tried
This seems to be a really simple query, but somehow I keep getting errors...
I am running an RMI server on a VM, but I keep getting this
im trying to fix this while loop but keep running into errors. Basically lets
I'm running some code through JSHint and I keep getting the following error: Don't

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.