"nullpointerexception" error while switching activity

0

I have a problem and I wish someone could fix it for me. I am a newbie in the java and android programming business, I developed a project that I tested and in debug mode ran everything right. But when I compiled and uploaded the project on google play and installed it on my phone, I was able to login, however when I enter the next activity, the stick 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 you can stay a bit 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>

Remember that the line that is giving the stick is the code: lbNome.setText(nm); .

I suspected that it could be something with the database or how I was creating a new connection to each activity, however it can not be a bank because in main it can access the database, make the select and check if the user exists. Suspecting the connection, I created a connection class where I create only one connection at the time of user authentication. Can anyone help me?

    
asked by anonymous 27.11.2015 / 18:21

1 answer

0

The variable nm is null, so the error.

Probably the problem is in the line below:

  

String nm = name.toUpperCase ();

Check the variable name and see if there is any value in it before performing "toUpperCase".

    
27.11.2015 / 20:02