Witam. Jestem początkujący w javie i mam problem w internecie znalazłem jak odczytać datę z ale po uruchomieniu aplikacji wyskakuje aplikacja została niespodziewanie zatrzymana. A jak zostawiłem tylko formatowanie daty bez jej wyświetlania to program się uruchomił.

Kod z klasy:

import android.app.*; 
import android.os.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.content.Context;
import android.widget.RemoteViews;
import android.widget.*;
import android.view.*;
import java.util.TimeZone;

public class MainActivity extends Activity {

TextView t1;
TextView t2;

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

SimpleDateFormat SimpleDateHere = new SimpleDateFormat("dd-MM-yyyy kk:mm:ss (Z)");
t1.setText(SimpleDateHere.format(new Date()));

SimpleDateFormat simpleDateThere = new SimpleDateFormat("dd-MM-yyyy kk:mm:ss (Z)");
simpleDateThere.setTimeZone(TimeZone.getTimeZone("Japan"));
t2.setText(simpleDateThere.format(new Date()));
}
}

Kod z układu graficznego:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="center" >

<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

<TextView
android:id="@+id/tvv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>

Resztę plików nie ruszałem.
Kod skopiowany z internetu to:(tylko go trochę przerobiłem bo ten kod był na komputer)

SimpleDateFormat SimpleDateHere = new SimpleDateFormat("dd-MM-yyyy kk:mm:ss (Z)");
t1.setText(SimpleDateHere.format(new Date()));

SimpleDateFormat simpleDateThere = new SimpleDateFormat("dd-MM-yyyy kk:mm:ss (Z)");
simpleDateThere.setTimeZone(TimeZone.getTimeZone("Japan"));
t2.setText(simpleDateThere.format(new Date()));

Link do projektu z internetu:
http://programowanie.opole.pl/archives/2333