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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:26:19+00:00 2026-05-31T14:26:19+00:00

I am trying to use a main,java to initiate 3 tabs, and have each

  • 0

I am trying to use a main,java to initiate 3 tabs, and have each pointing to a separate java / xml file. I was successfull in creating it for 4.0 platform using the #deprecation and it worked normally for 2.3.3 however after a while it has stopped working. I have run through debug and cannot figure out what the problem is. Any help would be appreciated.
Attached is the main.java / main.xml and the log. Let me know if you need any more.

Main.java

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class Main extends TabActivity {

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

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost(); // The activity TabHost
        TabHost.TabSpec spec; // Resusable TabSpec for each tab
        Intent intent; // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, Joke.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("Joke")
                .setIndicator("", res.getDrawable(R.drawable.ic_tab_joke))
                .setContent(intent);
        tabHost.addTab(spec);

        // Do the same for the other tabs
        intent = new Intent().setClass(this, Picture.class);
        spec = tabHost.newTabSpec("Picture")
                .setIndicator("", res.getDrawable(R.drawable.ic_tab_picture))
                .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Video.class);
        spec = tabHost.newTabSpec("Video")
                .setIndicator("", res.getDrawable(R.drawable.ic_tab_video))
                .setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(1);
    }
}

Main.xml

<?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:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="0dp" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:tabStripEnabled="false" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>

</TabHost>

LOG

03-15 16:26:49.625: I/ActivityManager(61): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.oftheday/.Main } from pid 132
03-15 16:26:49.805: I/ActivityManager(61): Start proc com.example.oftheday for activity com.example.oftheday/.Main: pid=345 uid=10035 gids={3003}
03-15 16:26:50.365: I/ARMAssembler(61): generated scanline__00000177:03515104_00001002_00000000 [ 87 ipp] (110 ins) at [0x444ea6f0:0x444ea8a8] in 423460 ns
03-15 16:26:50.964: D/AndroidRuntime(345): Shutting down VM
03-15 16:26:50.964: W/dalvikvm(345): threadid=1: thread exiting with uncaught exception (group=0x40015560)
03-15 16:26:50.984: E/AndroidRuntime(345): FATAL EXCEPTION: main
03-15 16:26:50.984: E/AndroidRuntime(345): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.oftheday/com.example.oftheday.Main}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.oftheday/com.example.oftheday.Joke}: java.lang.NullPointerException
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.os.Looper.loop(Looper.java:123)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.ActivityThread.main(ActivityThread.java:3683)
03-15 16:26:50.984: E/AndroidRuntime(345):  at java.lang.reflect.Method.invokeNative(Native Method)
03-15 16:26:50.984: E/AndroidRuntime(345):  at java.lang.reflect.Method.invoke(Method.java:507)
03-15 16:26:50.984: E/AndroidRuntime(345):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-15 16:26:50.984: E/AndroidRuntime(345):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-15 16:26:50.984: E/AndroidRuntime(345):  at dalvik.system.NativeStart.main(Native Method)
03-15 16:26:50.984: E/AndroidRuntime(345): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.oftheday/com.example.oftheday.Joke}: java.lang.NullPointerException
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.ActivityThread.startActivityNow(ActivityThread.java:1487)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.widget.TabHost.setCurrentTab(TabHost.java:326)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.widget.TabHost.addTab(TabHost.java:216)
03-15 16:26:50.984: E/AndroidRuntime(345):  at com.example.oftheday.Main.onCreate(Main.java:27)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-15 16:26:50.984: E/AndroidRuntime(345):  ... 11 more
03-15 16:26:50.984: E/AndroidRuntime(345): Caused by: java.lang.NullPointerException
03-15 16:26:50.984: E/AndroidRuntime(345):  at java.io.Reader.<init>(Reader.java:65)
03-15 16:26:50.984: E/AndroidRuntime(345):  at java.io.InputStreamReader.<init>(InputStreamReader.java:122)
03-15 16:26:50.984: E/AndroidRuntime(345):  at java.io.InputStreamReader.<init>(InputStreamReader.java:59)
03-15 16:26:50.984: E/AndroidRuntime(345):  at com.example.oftheday.Joke.DownloadText(Joke.java:62)
03-15 16:26:50.984: E/AndroidRuntime(345):  at com.example.oftheday.Joke.onCreate(Joke.java:19)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-15 16:26:50.984: E/AndroidRuntime(345):  ... 20 more
03-15 16:26:50.994: W/ActivityManager(61):   Force finishing activity com.example.oftheday/.Main

From what I can understand it is pointing to line 27 of main.java however the line is
tabHost.addTab(spec); and i cannot see any problem with is.

Appreciate the help 😀

EDIT 1 – Joke.java

package com.example.oftheday;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Joke extends Activity {

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

        String str = DownloadText("test.com/text.txt"); // line 19
        TextView jokeview = new TextView(this);
        jokeview.setText(str);

        TextView textview = new TextView(this);
        textview.setText("" + str);
        setContentView(R.layout.joke);

    }

    private InputStream OpenHttpConnection(String urlString) throws IOException {
        InputStream in = null;
        int response = -1;
        URL url = new URL(urlString);
        URLConnection conn = url.openConnection();
        if (!(conn instanceof HttpURLConnection))
            throw new IOException("Not an HTTP connection");
        try {
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setAllowUserInteraction(false);
            httpConn.setInstanceFollowRedirects(true);
            httpConn.setRequestMethod("GET");
            httpConn.connect();
            response = httpConn.getResponseCode();
            if (response == HttpURLConnection.HTTP_OK) {
                in = httpConn.getInputStream();
            }
        } catch (Exception ex) {
            throw new IOException("Error connecting");
        }
        return in;
    }

    private String DownloadText(String URL) {
        int BUFFER_SIZE = 2000;
        InputStream in = null;
        try {
            in = OpenHttpConnection(URL);
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            return "";
        }
        InputStreamReader isr = new InputStreamReader(in); // line 62
        int charRead;
        String str = "";
        char[] inputBuffer = new char[BUFFER_SIZE];
        try {
            while ((charRead = isr.read(inputBuffer)) > 0) {
                // ---convert the chars to a String---
                String readString = String
                        .copyValueOf(inputBuffer, 0, charRead);
                str += readString;
                inputBuffer = new char[BUFFER_SIZE];
            }
            in.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "";
        }
        return str;
    }
}

Joke.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:orientation="vertical" >

    <TextView
        android:id="@+id/jotd"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

</LinearLayout>
  • 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-31T14:26:21+00:00Added an answer on May 31, 2026 at 2:26 pm

    The exception is cascaded all the way to main.java but the cause of the exception is lower in the stack trace:

    03-15 16:26:50.984: E/AndroidRuntime(345): Caused by: java.lang.NullPointerException
    03-15 16:26:50.984: E/AndroidRuntime(345):  at java.io.Reader.<init>(Reader.java:65)
    03-15 16:26:50.984: E/AndroidRuntime(345):  at java.io.InputStreamReader.<init>(InputStreamReader.java:122)
    03-15 16:26:50.984: E/AndroidRuntime(345):  at java.io.InputStreamReader.<init>(InputStreamReader.java:59)
    03-15 16:26:50.984: E/AndroidRuntime(345):  at com.example.oftheday.Joke.DownloadText(Joke.java:62)
    03-15 16:26:50.984: E/AndroidRuntime(345):  at com.example.oftheday.Joke.onCreate(Joke.java:19)
    03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    03-15 16:26:50.984: E/AndroidRuntime(345):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    03-15 16:26:50.984: E/AndroidRuntime(345):  ... 20 more
    

    So you issue is within com.example.oftheday.Joke.DownloadText Could you post the code for that class? You can also put a breakpoint on Eclipse. See how to do it here.


    Update:

    Ok first of all have a look at naming conventions. Some bits were hard to read.

    Secondly, I think the problem is that you are trying to open “test.com/text.txt” which is non existent and therefore, inside OpenHttpConnection(), the condition response == HttpURLConnection.HTTP_OK is never true hence the InputStream returned remains null (giving you the NullPointerException)

    Hope it helps.

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

Sidebar

Related Questions

I am trying to use DOM Parser in Java to parse a small XML
I am trying to use the java Mail API in my program, i have
I am trying to use FindClass on one of my Java file in Android,
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I am trying use a Java Uploader in a ROR app (for its ease
Trying to use an excpetion class which could provide location reference for XML parsing,
Trying to use GnuPG with Delphi (Win32). I need to sign some file with
I'm trying to use some Java-classes with Clojure. I've tried it with Scala with
I'm trying to use Java Opencl from within jruby, but am encountering a problem
I'm trying to use JNI and getting java.lang.UnsatisfiedLinkError. Unlike the other million questions asked

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.