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

The Archive Base Latest Questions

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

I am modifying someone else’s code, and just trying to add a fourth checkbox

  • 0

I am modifying someone else’s code, and just trying to add a fourth checkbox to the following dialog:

<?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">
<CheckBox 
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp" 
    android:layout_width="wrap_content" 
    android:text="@string/vinai_full" 
    android:checked="true"
    android:id="@+id/cb_vinai" 
    android:layout_height="wrap_content"/>
<CheckBox 
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp" 
    android:layout_width="wrap_content" 
    android:text="@string/suttan_full" 
    android:checked="true"
    android:id="@+id/cb_suttan"
    android:layout_height="wrap_content"/>
<CheckBox 
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp" 
    android:layout_width="wrap_content"
    android:text="@string/abhidum_full" 
    android:checked="true"
    android:id="@+id/cb_abhidham" 
    android:layout_height="wrap_content"/>
<Button 
    android:text="@string/ok"  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/okcatebtn" 
    android:layout_marginTop="20dp"
    android:layout_marginBottom="10dp"
    android:layout_gravity="center" 
    />
</LinearLayout>

The fourth checkbox is:

<CheckBox 
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp" 
    android:layout_width="wrap_content"
    android:text="@string/etc_full" 
    android:checked="true"
    android:id="@+id/cb_etc" 
    android:layout_height="wrap_content"/>

When I add it in, the apk compiles fine, but the program crashes on startup:

E/AndroidRuntime( 1470): FATAL EXCEPTION: main
E/AndroidRuntime( 1470): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.yuttadhammo.tipitaka/org.yuttadhammo.tipitaka.SelectBookActivity}: java.lang.ClassCastException: android.widget.Gallery
E/AndroidRuntime( 1470):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
E/AndroidRuntime( 1470):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
E/AndroidRuntime( 1470):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime( 1470):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
E/AndroidRuntime( 1470):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1470):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1470):    at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 1470):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1470):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 1470):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 1470):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 1470):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1470): Caused by: java.lang.ClassCastException: android.widget.Gallery
E/AndroidRuntime( 1470):    at org.yuttadhammo.tipitaka.SelectBookActivity.onCreate(SelectBookActivity.java:586)
E/AndroidRuntime( 1470):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 1470):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
E/AndroidRuntime( 1470):    ... 11 more

This is even though the dialog is not loaded at startup. If I replace the third checkbox with the fourth one, there is no crash, so it seems like for some reason it is simply not accepting a fourth element. Why would that be?

EDIT: Here’s the code leading up to the error, but I don’t understand how it is related, since it refers to an element in a differing layout file:

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

    main =  View.inflate(this, R.layout.main, null);
    setContentView(main);

    searchHistoryDBAdapter = new SearchHistoryDBAdapter(SelectBookActivity.this);
    searchResultsDBAdapter = new SearchResultsDBAdapter(SelectBookActivity.this);
    bookmarkDBAdapter = new BookmarkDBAdapter(SelectBookActivity.this);

    Context context = getApplicationContext();
    prefs =  PreferenceManager.getDefaultSharedPreferences(context);

    MainTipitakaDBAdapter mainTipitakaDBAdapter = new MainTipitakaDBAdapter(this);
    try {
        mainTipitakaDBAdapter.open();
        if(mainTipitakaDBAdapter.isOpened()) {
            mainTipitakaDBAdapter.close();
        } else {
            startDownloader();
        }
    } catch (SQLiteException e) {
        Log.e ("Tipitaka","error:", e);
        startDownloader();
    }

    Resources res = getResources();
    final String [] cnames = res.getStringArray(R.array.category);

    textInfo = (TextView) findViewById(R.id.text_info);

and here’s main.xml:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:scrollbars="horizontal|vertical">
    <LinearLayout    
        android:id="@+id/LinearLayout01"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_gravity="center_horizontal"
            android:padding="3dp"
            android:id="@+id/about_header">

            <TextView
                android:id="@+id/about_text_1"
                android:layout_marginLeft="1dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/about_logo"
                android:layout_centerVertical="true"
                android:text="Android Tipitaka"
                android:textSize="24sp"
                android:textColor="@android:color/primary_text_dark_nodisable"/>    

        </RelativeLayout>       

        <View 
            android:background="@drawable/black_white_gradient"
            android:layout_width="match_parent"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="5dp"
            android:layout_height="2dp"/>
        <Gallery 
            android:layout_width="match_parent" 
            android:id="@+id/gallery_cate" 
            android:spacing="6dp" 
            android:gravity="center_vertical" 
            android:layout_height="60dp"/>

        <TextView
            android:id="@+id/book_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="@string/th_book_label"
            android:textSize="17sp"
        />

        <Gallery 
            android:id="@+id/gallery_ncate" 
            android:layout_width="match_parent" 
            android:layout_height="60dp"
            android:gravity="center_vertical"
            android:spacing="25dp"

        />
        <TextView
            android:id="@+id/text_info"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:lines="2"
            android:layout_marginBottom="5dp"
            android:layout_gravity="center_vertical|center_horizontal|center"
            android:gravity="center_vertical|center_horizontal"
            android:text=""
            android:textSize="17sp"
        />

        <RelativeLayout
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:id="@+id/main_buttons"
            android:layout_gravity="center_horizontal">
            <Button
                android:id="@+id/read_btn"
                android:layout_width="85dp" 
                android:layout_height="wrap_content"
                android:gravity="center_vertical|center_horizontal"
                android:layout_gravity="center_vertical|center_horizontal|center"
                android:text="@string/th_read"
                android:textStyle="bold"
                android:textSize="16dp"
                android:layout_marginRight="40dp"
            />
            <Button
                android:id="@+id/search_btn"
                android:text="@string/th_search"
                android:layout_toRightOf="@id/read_btn"
                android:layout_width="85dp" 
                android:layout_height="wrap_content"
                android:gravity="center_vertical|center_horizontal"
            android:layout_gravity="center_vertical|center_horizontal|center"
                android:textStyle="bold"
                android:textSize="16dp"
            />
        </RelativeLayout>

</LinearLayout>
</ScrollView>
  • 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-02T23:43:19+00:00Added an answer on June 2, 2026 at 11:43 pm

    if text_info is in diffrent layout then use this

    textInfo = (TextView)your_layout.findViewById(R.id.text_info);
    

    instead of

    textInfo = (TextView)findViewById(R.id.text_info);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm modifying someone else's code where a query is performed using the following: DataSet
I'm modifying someone else's code which uses TCHAR extensively. Is it better form to
I'm trying to understand InstallShield (2009)/InstallScript on the fly, because I'm modifying someone else's
I am modifying some Flex code written by someone else. There is an mx:text
I'm stuck modifying someone else's source code, and unfortunately it's very strongly NOT documented.
I'm modifying a Firefox extension that has been written by someone else, and I'm
I'm stepping through someone else's code to find what's breaking mine under a certain,
I just wrote an answer for someone else and when testing It turns out
I have the following code and I was wondering if someone could look at
I'm modifying someone else's css and I try to make the page responsive with

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.