0

My app is getting crashed due this error

     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference

Now I know this is caused by some null reference but I'm Not able to figure it out, here's where exactly the problem happen, after pressing the alert key

beforeGenerate.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
 //------------------- This code is for generating the qr image----------------------

            String studentId = String.valueOf(takeText.getText());
            int dimension = 200;
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(studentId, null, Contents.Type.TEXT,
                    BarcodeFormat.QR_CODE.toString(), dimension);

   String fileName = "studentID";
            try {
                Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
                ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
                FileOutputStream fo = openFileOutput(fileName, Context.MODE_PRIVATE);
                fo.write(bytes.toByteArray());
                fo.close();
// going for next activity and show QR
            Intent i = new Intent(idEnterActivity.this, showQR.class);
            startActivity(i);
            } catch (Exception e) {
        }
        }
    });

I'm trying to go to this activity

public class showQR extends ActionBarActivity {

public void onCreate(Bundle savedInstantState){
    super.onCreate(savedInstantState);
    setContentView(R.layout.activity_show_qr);
    Context context = this;
    Intent i = getIntent();
    String fileName = i.getExtras().getString("fileName");
    try {
        Bitmap bitmap = BitmapFactory.decodeStream(context
                .openFileInput(fileName));
        ImageView gg = (ImageView)findViewById(R.id.qrCode);
        gg.setImageBitmap(bitmap);
    }
    catch(Exception e){

    }
}

}

this is my manifests file

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".splach"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Main"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".idEnterActivity"
        android:label="@string/title_activity_id_entet" >
    </activity>

    <activity
        android:name=".showQR"
        android:label="@string/abc_action_bar_home_description">
    </activity>

</application>

I'm newbie in programming, so please tell me what I'm messing :)

EDIT

That's the rest of logcat from

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
        at impresesnt.abedbayoun.impresent.showQR.onCreate(showQR.java:22)
        at android.app.Activity.performCreate(Activity.java:5933)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
  • The log should tell you exactly where it crashes. Add a logcat where the exact line of the exception is shown, and tell us what's on that line. – JHH Feb 25 '15 at 21:11
  • 2
    That said, it looks like your second activity tries to find a string extra "filename" but when you start the activity you don't pass any such parameter in the intent.... – JHH Feb 25 '15 at 21:13
  • Your exception tells you that the problem is with your `Bundle.getString()` - when there is no `Bundle` – GermaineJason Feb 25 '15 at 21:39
  • @JHH I added the logcat of line with errors – Abed Bayoun Feb 25 '15 at 22:37
  • Thank you both guys! Ya you were both right, I was missing the bundle – Abed Bayoun Feb 25 '15 at 23:16

0 Answers0