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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:04:33+00:00 2026-06-03T08:04:33+00:00

I am building a app in which i am trying to ask user to

  • 0

I am building a app in which i am trying to ask user to select the time, so i used datePicker and timePicker and a button set. So when he click on set button a dialog box comes and say like you have selected x date and x time or in any way a message should appear on screen like user have selected this time. So i built the code but as my app comes to that activity it always got forcefully stopped.There is no problem with the xml file relating to display the data because when i comment java lines of fetching the values from datePicker and timePicker, app works absolutely fine.
Still i am posting both files code for easy to understanding. also posting the log cat exception. I have removed all unnecessary code like import and packages and extra button etc To make it quick readable.

This is the code of .xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="10"
android:id="@+id/commonlayout" android:background="#FFFFFF">

<LinearLayout android:id="@+id/llheader"
    android:layout_width="fill_parent" android:layout_height="20dp"
     android:layout_weight="1"
     android:background="@drawable/bg">

    <RelativeLayout android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:layout_gravity="center"> <!--header-->
        <TextView
            android:id="@+id/txt_header"
            android:layout_width="wrap_content"          
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"/>            
        </RelativeLayout>           
</LinearLayout>
 <ScrollView 
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:layout_width="wrap_content"
    android:id="@+id/linearLayout1" android:orientation="vertical"
    android:layout_height="wrap_content" 
<DatePicker android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
  android:id="@+id/datePicker"></DatePicker>
<TimePicker android:id="@+id/timePicker"
    android:layout_width="wrap_content"   
  android:layout_height="wrap_content</TimePicker>
<TableRow android:id="@+id/tableRow1" android:layout_height="wrap_content"
    android:layout_width="match_parent" android:gravity="center">

    <Button android:id="@+id/btnSetDateTime"
        android:layout_height="wrap_content" android:text="Set"
        android:layout_width="wrap_content"/>
     <Button 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Next"                       
        android:id="@+id/btnNext1" />   
  </TableRow>
 </LinearLayout>
 </ScrollView>    
<LinearLayout android:id="@+id/lldata"
    android:layout_weight="8" android:layout_width="fill_parent"
    android:layout_height="0dp" android:background="#FFFFFF">           
</LinearLayout>

<LinearLayout android:id="@+id/llfooter"
    android:layout_width="fill_parent"
    android:orientation="horizontal" android:layout_height="20dp"
    android:visibility="visible" 
    android:layout_margin="0dp">     
</LinearLayout>

This is the code of TimeDate.java:

public class TimeDate extends Activity
{


Button  btnNext;
private TextView dateText;
 public void onCreate(Bundle savedInstanceState)
 {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.time_date);
        btnNext=(Button)this.findViewById(R.id.btnNext1);           
        btnNext.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) 
            {

                    Intent myintent = new  Intent(TimeDate.this, Next.class);
                    startActivity(myintent);
                    finish();
                    }
        });
        ScrollView DTPicker = (ScrollView) View.inflate(TimeDate.this,R.layout.time_date, null);

        Button  btnSet = (Button) DTPicker.findViewById(R.id.btnSetDateTime);
        final   DatePicker dp = (DatePicker) DTPicker.findViewById(R.id.datePicker);
        final   TimePicker tp = (TimePicker) DTPicker.findViewById(R.id.timePicker);

        btnSet.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                String strDateTime = dp.getYear() + "-" + (dp.getMonth() + 1) + "-" + dp.getDayOfMonth() + " "+ tp.getCurrentHour() + ":" + tp.getCurrentMinute();}});

       AlertDialog alert = new AlertDialog.Builder(TimeDate.this).create();
        alert.setTitle("Reminder");
        alert.setView(DTPicker);
        alert.show();

 }       
}

This is the logcat exception:

04-27 11:48:24.830: D/AndroidRuntime(812): Shutting down VM
04-27 11:48:24.830: W/dalvikvm(812): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-27 11:48:24.851: E/AndroidRuntime(812): FATAL EXCEPTION: main
04-27 11:48:24.851: E/AndroidRuntime(812): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ogtpl.android/com.ogtpl.android.TimeDate}: java.lang.ClassCastException: android.widget.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-06-03T08:04:35+00:00Added an answer on June 3, 2026 at 8:04 am

    Don’t do anything extra, Your code is just prefect. Just remove the code of ScrollLayout or its attribute wherever you are using that.
    Lemme write the updated code for you from ScrollLayout

     final   DatePicker dp = (DatePicker) findViewById(R.id.datePicker);
            final   TimePicker tp = (TimePicker) findViewById(R.id.timePicker);
            btnSet.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    String strDateTime = dp.getYear() + "-" + (dp.getMonth() + 1) + "-" + dp.getDayOfMonth() + " "+ tp.getCurrentHour() + ":" + tp.getCurrentMinute();
    
                    Toast.makeText(TimeDate.this, "User selected " + strDateTime + "Time", Toast.LENGTH_LONG).show(); //Generate a toast only if you want 
                    finish();   // If you want to continue on that TimeDateActivity
                     // If you want to go to new activity that code you can also write here
                }});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an app for which I need to set up cron jobs.
I'm building a Rails app which creates a bookmarklet file for each user upon
I am building a ios app for ipad, in which the user will be
I'm building an AJAX app which animates in content dynamically. Since all links are
I am building an iphone app which allows people to update an xml file
I have an app i building which is a simple naviagtion app. I do
I am building an app with complex data which I use arrays for. Some
I'm building a nice app with CodeIgniter and Ajax JQuery which returns finally a
I'm am building a web app and need a text to speech which highlights
I´m building an asp.net app, which technology I should use to get AJAX capabilities?

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.