0
I have a problem and I wish someone could solve it for me. I am new in the field of java and android programming, I developed a project in which I tested and in debug mode ran everything right. But when I compiled and uploaded the project to google play and installed it on my mobile phone, I was able to log in, however when it enters the next Activity, the dick app. So when I sent the report, what I got was:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobilegenio.geniomobile/com.mobilegenio.geniocondominios.principalActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2436) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2498) at android.app.ActivityThread.access$900(ActivityThread.java:179) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5641) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1288) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1104) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.mobilegenio.geniocondominios.principalActivity.onCreate(principalActivity.java:259) at android.app.Activity.performCreate(Activity.java:5484) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400) ... 11 more
Follow my Activity code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.principal);
Intent intent = getIntent();
String userId = intent.getStringExtra("userId");
Button btnReport = (Button)findViewById(R.id.btnRp);
Button btnNotas = (Button)findViewById(R.id.btnNs);
selectUser = "SELECT * FROM users WHERE Id = '" + userId + "'";
connect = CONN("xxxxx", "xxxx", "xxxxx", "xxxxxxx");
if(QuerySQL(selectUser)) {
lbNome = (TextView)findViewById(R.id.lbNomeUser);
lbAp = (TextView)findViewById(R.id.lbAp);
lbBloco = (TextView)findViewById(R.id.lbBloco);
nomeCondominio = (TextView)findViewById(R.id.lbNC);
String nm = nome.toUpperCase();
lbNome.setText(nm); //<----------------- AQUI DA PAU
lbAp.setText(ap);
lbBloco.setText(bloco);
String selectCondominio = "SELECT TOP 1 * FROM condominios WHERE Id = '" + condominio_Id + "'";
QuerySQLCondominio(selectCondominio);
nomeCondominio.setText(lbNomeCondominio);
if(isSindico){
btnReport.setText("REPORTES");
btnNotas.setText("ESCREVER NOTA");
}else{
btnReport.setText("REPORTAR AO SÍNDICO");
btnNotas.setText("NOTAS DO SÍNDICO");
}
}else{
Toast.makeText(this, "Login ou Senha inválidos!", Toast.LENGTH_SHORT).show();
}
}
Also my xml so it can be a little clearer:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<TableRow
android:layout_width="match_parent"
android:layout_height="75dp"
android:orientation="horizontal"
android:background="#197cd0"
android:layout_gravity="center_horizontal"
android:layout_weight="0.07">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:weightSum="1" >
<ImageView
android:layout_width="82dp"
android:layout_height="match_parent"
android:id="@+id/imageView3"
android:src="@drawable/logotopo"
android:paddingLeft="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:id="@+id/lbNC"
android:textColor="@color/corTextoONAzul"
android:paddingTop="10dp"
android:textSize="18dp" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_gravity="center_horizontal"
android:layout_weight="0.07"
android:background="#f2f3f6"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:layout_width="140dp"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/lbNomeUser"
android:textColor="@color/colorPrimary"
android:paddingTop="10dp"
android:paddingLeft="15dp"
android:textStyle="bold"
android:paddingRight="15dp"
android:layout_weight="0.65"
android:textSize="17dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="AP:"
android:id="@+id/textView3"
android:textStyle="bold"
android:paddingTop="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="100"
android:id="@+id/lbAp"
android:textColor="@color/colorPrimary"
android:paddingRight="15dp"
android:paddingTop="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Bloco:"
android:id="@+id/textView"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="1"
android:textColor="@color/colorPrimary"
android:id="@+id/lbBloco" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:background="@drawable/bg"
android:gravity="top|left"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:paddingTop="10dp"
android:paddingBottom="20dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight=".05">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text=""
android:id="@+id/btnRp"
android:layout_weight=".5"
android:background="@color/colorPrimary"
android:textColor="@color/corTextoONAzul"
android:layout_marginRight="5dp"
android:layout_marginBottom="10dp"
android:drawableTop="@drawable/reportar"
android:drawablePadding="-10dp"
android:paddingTop="20dp"
android:textSize="10sp"
android:paddingLeft="9dp"
android:paddingRight="9dp"
android:onClick="reportarProblema"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="@string/btnAcordo"
android:id="@+id/btnAcordo"
android:layout_weight=".5"
android:background="@color/colorPrimary"
android:textColor="@color/corTextoONAzul"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp"
android:drawableTop="@drawable/acordo"
android:drawablePadding="-10dp"
android:paddingTop="20dp"
android:textSize="10sp"
android:onClick="acordarVizinho"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight=".05">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="@string/btnServico"
android:id="@+id/btnServico"
android:layout_weight=".5"
android:background="@color/colorPrimary"
android:textColor="@color/corTextoONAzul"
android:layout_marginRight="5dp"
android:layout_marginBottom="10dp"
android:textSize="10sp"
android:drawableTop="@drawable/servicos"
android:drawablePadding="-10dp"
android:paddingTop="20dp"
android:onClick="servicos"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text=""
android:id="@+id/btnNs"
android:layout_weight=".5"
android:background="@color/colorPrimary"
android:textColor="@color/corTextoONAzul"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp"
android:textSize="10sp"
android:drawableTop="@drawable/notas"
android:drawablePadding="-10dp"
android:paddingTop="20dp"
android:onClick="notasSindico"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight=".05">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="@string/btnAgenda"
android:id="@+id/btnAgenda"
android:layout_weight=".5"
android:background="@color/colorPrimary"
android:textColor="@color/corTextoONAzul"
android:layout_marginRight="5dp"
android:layout_marginBottom="10dp"
android:textSize="10sp"
android:drawableTop="@drawable/agenda"
android:drawablePadding="-10dp"
android:paddingTop="20dp"
android:onClick="agendamentos"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="@string/btnCamera"
android:id="@+id/btnCam"
android:layout_weight=".5"
android:background="@color/colorPrimary"
android:textColor="@color/corTextoONAzul"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp"
android:textSize="10sp"
android:drawableTop="@drawable/tirarfoto"
android:drawablePadding="-10dp"
android:paddingTop="20dp"
android:onClick="fotos"/>
</LinearLayout>
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="#485d8a"></TableRow>
</LinearLayout>
Remembering that the line you’re taking is the code: lbNome.setText(nm);
.
I suspected that it could be something with the database or as I was creating a new connection to each Activity, however it can not be database because in the main it can access the database, select and check if there is the user. Suspecting it was the connection, I created a connection class where I create only one connection at the time of user authentication.
Can someone help me?
then, this variable receives a data from the database, but I have checked and is returning normally.
– judeugabriel
@judeugabriel Ok. Check that the id R.id.lbNomeUser is actually in your main layout file.
– Arubu
it appears, but I had problems recognizing the Uttons, I had to add an item in the manifest so that it was possible, for precaution I already inserted the items of the textviews in the manifest also but I was not successful!
– judeugabriel
Why running the debug of my project it runs right and in the release version of this problem?
– judeugabriel