mercredi 25 février 2015

program stopping due java.lang.NullPointerException: Attempt to invoke virtual method [duplicate]




This question already has an answer here:




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)



Aucun commentaire:

Enregistrer un commentaire