传递日期从日历中选择后 [英] Passing the date after selecting it from the calendar

查看:145
本文介绍了传递日期从日历中选择后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家,我遇到一个问题,通过日期从日历到我的Create_Event.class。最初日期的TextView显示文本然后,当我点击选择日期按钮,在日历页面将显示,日期应该是传递给TextView中,原本显示为文本。我试着用intent.putExtra通过从日历页至Create_Events页面日期编码,但我由于NullPointerException异常得到了强制关闭的错误。谁能帮我解决这个问题?非常感谢。

有关参考,C $ CS的$:

Calendar.java

  @覆盖
                公共无效的onClick(视图查看)
                {
                    字符串date_month_year =(字符串)view.getTag();
                    selectedDayMonthYearButton.setText(新的StringBuilder()追加(选择。)追加(date_month_year));

                    意图K =新的意图(Calendar_Event.this,Create_Events.class);
                    k.putExtra(passdate,date_month_year);
                 startActivity(k)的;
 

Create_Event.java

 意向意图= this.getIntent();
        如果(意向== NULL)
        {
         串strData是= intent.getExtras()的getString(passdate);
         TextView的txtDate =(TextView中)findViewById(R.id.textDate);
         txtDate.setText(strData是);
         }
        其他
        {

        }
 

***本来,如果(意向== NULL)是,如果(意向!= NULL),我想改变它的工作,但事实并非如此。 :P

更新了logcat的:

  12月9日至7日:03:28.177:E / AndroidRuntime(1033):致命异常:主要
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):java.lang.RuntimeException的:无法启动的活动ComponentInfo {main.page/main.page.Create_Events}:显示java.lang.NullPointerException
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在android.app.ActivityThread.access $ 600(ActivityThread.java:123)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1147)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在android.os.Handler.dispatchMessage(Handler.java:99)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在android.os.Looper.loop(Looper.java:137)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在android.app.ActivityThread.main(ActivityThread.java:4424)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在java.lang.reflect.Method.invokeNative(本机方法)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在java.lang.reflect.Method.invoke(Method.java:511)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在dalvik.system.NativeStart.main(本机方法)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):由:显示java.lang.NullPointerException
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在main.page.Create_Events.onCreate(Create_Events.java:261)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在android.app.Activity.performCreate(Activity.java:4465)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12月九日日至7日:03:28.177:E / AndroidRuntime(1033):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
 

任何帮助将是很大的AP preciated!再次感谢。

更新:

 捆绑包= getIntent()getExtras()。
    如果(捆绑!= NULL)
    {

        字符串日期= bundle.getString(日);
        TextView的txtDate =(TextView中)findViewById(R.id.textDate);
        txtDate.setText(日期);
    }
 

解决方案

使用捆绑在Create_Events活动得到更新。传递数据之前,您首先需要检查它为空或不是。<​​/ P>

 捆绑包= getIntent()getExtras()。

如果(捆绑!= NULL)
{
    字符串日期= bundle.getString(passdate);
}
 

  

包一般用于各种活动之间传递数据。它   取决于你要通过,但捆的是什么类型的值   保存所有类型的值,并传递给新的活动。

everyone I am encountering a problem with passing the date from the calendar to my Create_Event.class. Initially the date textView displays "text" then when I click the "Select the date" button the calendar page will show and the date is supposed to be passed to textView that originally displays "text". I tried coding using intent.putExtra to pass the date from the calendar page to the Create_Events page but I got a force close error due to NullPointerException. Can anyone help me with this issue? Thanks a lot.

For reference, the codes:

Calendar.java

@Override
                public void onClick(View view)
                {
                    String date_month_year = (String)view.getTag();
                    selectedDayMonthYearButton.setText(new StringBuilder().append("Selected:").append(date_month_year));

                    Intent k = new Intent(Calendar_Event.this, Create_Events.class);
                    k.putExtra("passdate", date_month_year);
                 startActivity(k);

Create_Event.java

 Intent intent = this.getIntent();
        if(intent == null)
        {
         String strdata = intent.getExtras().getString("passdate");
         TextView txtDate = (TextView) findViewById(R.id.textDate);
         txtDate.setText(strdata);
         }
        else
        {

        }

***Originally the if(intent == null) is if(intent != null), I thought changing it would work but it doesn't. :P

Updated the logcat:

09-07 12:03:28.177: E/AndroidRuntime(1033): FATAL EXCEPTION: main
09-07 12:03:28.177: E/AndroidRuntime(1033): java.lang.RuntimeException: Unable to start activity ComponentInfo{main.page/main.page.Create_Events}: java.lang.NullPointerException
09-07 12:03:28.177: E/AndroidRuntime(1033):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
09-07 12:03:28.177: E/AndroidRuntime(1033):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
09-07 12:03:28.177: E/AndroidRuntime(1033):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
09-07 12:03:28.177: E/AndroidRuntime(1033):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
09-07 12:03:28.177: E/AndroidRuntime(1033):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-07 12:03:28.177: E/AndroidRuntime(1033):     at android.os.Looper.loop(Looper.java:137)
09-07 12:03:28.177: E/AndroidRuntime(1033):     at android.app.ActivityThread.main(ActivityThread.java:4424)
09-07 12:03:28.177: E/AndroidRuntime(1033):     at java.lang.reflect.Method.invokeNative(Native Method)
09-07 12:03:28.177: E/AndroidRuntime(1033):     at java.lang.reflect.Method.invoke(Method.java:511)
09-07 12:03:28.177: E/AndroidRuntime(1033):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-07 12:03:28.177: E/AndroidRuntime(1033):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-07 12:03:28.177: E/AndroidRuntime(1033):     at dalvik.system.NativeStart.main(Native Method)
09-07 12:03:28.177: E/AndroidRuntime(1033): Caused by: java.lang.NullPointerException
09-07 12:03:28.177: E/AndroidRuntime(1033):     at main.page.Create_Events.onCreate(Create_Events.java:261)
09-07 12:03:28.177: E/AndroidRuntime(1033):     at android.app.Activity.performCreate(Activity.java:4465)
09-07 12:03:28.177: E/AndroidRuntime(1033):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
09-07 12:03:28.177: E/AndroidRuntime(1033):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)

Any help would be greatly appreciated! Thanks again.

Updated:

 Bundle bundle = getIntent().getExtras();  
    if(bundle != null)
    {

        String date = bundle.getString("date");
        TextView txtDate = (TextView) findViewById(R.id.textDate);
        txtDate.setText(date);          
    }

解决方案

Use Bundle in Create_Events Activity to get date. Before passing data you first need to check it is null or not.

Bundle bundle = getIntent().getExtras();

if(bundle != null)
{
    String date = bundle.getString("passdate");
}

Bundle generally use for passing data between various Activities. It depends on you what type of values you want to pass but bundle can hold all types of values and pass to the new activity.

这篇关于传递日期从日历中选择后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆