Hello I am trying to start activity from one to activity to other one but i get error
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bsine_000.baseinas/com.example.bsine_000.baseinas.registracija}: java.lang.NullPointerException
here is the code:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button etprisijungti;
EditText etelpastas, etslaptazodis;
TextView reglink;
saugykla saugykla;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etprisijungti = (Button) findViewById(R.id.etprisijungti);
etelpastas = (EditText) findViewById(R.id.etelpastas);
etslaptazodis = (EditText) findViewById(R.id.etslaptazodis);
reglink = (TextView) findViewById(R.id.reglink);
reglink.setOnClickListener(this);
etprisijungti.setOnClickListener(this);
saugykla = new saugykla(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.etprisijungti:
vartotojas vartotojas = new vartotojas(null,null);
saugykla.saugoti(vartotojas);
saugykla.vartotojas_prisijunges(true);
startActivity(new Intent(this, pagrindinis.class));
break;
case R.id.reglink:
startActivity(new Intent(this, registracija.class));
break;
}
}
}
code where app crashes is
case R.id.reglink:
startActivity(new Intent(this, registracija.class));
break;
first case works fine code is exactly the same here is registracija class:
public class registracija extends AppCompatActivity implements View.OnClickListener {
Button etregistruotis;
EditText etelpastas, etslaptazodis;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registracija);
etregistruotis = (Button) findViewById(R.id.reglink)
etelpastas = (EditText) findViewById(R.id.etelpastas);
etslaptazodis = (EditText) findViewById(R.id.etslaptazodis);
etregistruotis.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.etregistruotis:
String elpastas = etelpastas.getText().toString();
String slaptazdodis = etslaptazodis.getText().toString();
break;
}
}
}
Logcat :
05-25 10:45:36.401 23721-23721/com.example.bsine_000.baseinas W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41241438)
05-25 10:45:36.411 23721-23721/com.example.bsine_000.baseinas E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bsine_000.baseinas/com.example.bsine_000.baseinas.registracija}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
at android.app.ActivityThread.access$700(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4960)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.bsine_000.baseinas.registracija.onCreate(registracija.java:23)
at android.app.Activity.performCreate(Activity.java:5203)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
at android.app.ActivityThread.access$700(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4960)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
activity main
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:text="El.pastas"/>
<EditText
android:id="@+id/etelpastas"
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:text="slaptazodis"/>
<EditText
android:id="@+id/etslaptazodis"
android:inputType="textPassword"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/etprisijungti"
android:text="Prisijungti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:enabled="true" />
<TextView
android:id="@+id/reglink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textStyle="bold"
android:padding="10dp"
android:layout_gravity="center_horizontal"
android:text="Registruotis"
android:clickable="true"
android:linksClickable="true" />
Activity registracija
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:text="El.pastas"/>
<EditText
android:id="@+id/etelpastas"
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:text="slaptazodis"/>
<EditText
android:id="@+id/etslaptazodis"
android:inputType="textPassword"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/etregistruotis"
android:text="Registruotis"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>