Note that there are some explanatory texts on larger screens.

plurals
  1. POdisplaying date & time
    text
    copied!<p>I want to display date and time separately, but application crashes instead. If i remove time side of it, then it doesn't crash. But I really need to display date on one place and time separitely on the other place.</p> <pre><code> // date &amp; time \\ // date dateatm = (TextView) findViewById(R.id.date); Calendar currentDate = Calendar.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MMM/dd"); String dateNow = formatter.format(currentDate.getTime()); dateatm.setText(dateNow); // time timeatm = (TextView) findViewById(R.id.time); Calendar currentTime = Calendar.getInstance(); SimpleDateFormat värk = new SimpleDateFormat("HH:mm:ss"); String timeNow = värk.format(currentTime.getTime()); timeatm.setText(timeNow); </code></pre> <p>XML:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;TextView android:text="Tere " android:id="@+id/tvTere" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="20dp"&gt;&lt;/TextView&gt; &lt;TextView android:id="@+id/date" android:text="kuupäev" android:layout_width="fill_parent" android:textSize="20dp" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:gravity="center"&gt;&lt;/TextView&gt; &lt;TextView android:id="@+id/time" android:text="kellaaeg" android:layout_width="fill_parent" android:textSize="20dp" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:gravity="center"&gt;&lt;/TextView&gt; </code></pre> <h2> </h2> <p>Error in </p> <pre><code>08-10 16:22:13.614: ERROR/AndroidRuntime(531): FATAL EXCEPTION: main 08-10 16:22:13.614: ERROR/AndroidRuntime(531): java.lang.RuntimeException: Unable to start activity ComponentInfo{viimane.voimalus/viimane.voimalus.MainStuff}: java.lang.NullPointerException 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at android.os.Handler.dispatchMessage(Handler.java:99) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at android.os.Looper.loop(Looper.java:123) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at android.app.ActivityThread.main(ActivityThread.java:3683) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at java.lang.reflect.Method.invokeNative(Native Method) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at java.lang.reflect.Method.invoke(Method.java:507) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at dalvik.system.NativeStart.main(Native Method) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): Caused by: java.lang.NullPointerException 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at viimane.voimalus.MainStuff.onCreate(MainStuff.java:52) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 08-10 16:22:13.614: ERROR/AndroidRuntime(531): ... 11 more </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload