I have 2 activities let's say activity Alpha and activity Beta.
in my AlphaActivity.class i have the code below:
...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
cDatabase.addValueEventListener(new ValueEventListener() {
public static final String TAG = "XD";
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot snapshot : dataSnapshot.getChildren()) {
String u = snapshot.child("username").getValue().toString(),
p = snapshot.child("phone").getValue().toString(),
ad = snapshot.child("address").getValue().toString(),
f = snapshot.child("floor").getValue().toString(),
ns = snapshot.child("notes").getValue().toString();
Address a = new Address(u, p, ad, f, ns);
infoArray.add(a.address);
nameArray.add(a.name);
phoneArray.add(a.phone);
writeListView();
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Toast.makeText(ProfileActivity.this, "Action canceled!", Toast.LENGTH_SHORT).show();
}
});
}
...
Whenever i run that activity works like a charm. I have a button in this one where i start the Beta activity onClick like so:
public void betaMethod(View view) {
finish();
Intent intent = new Intent(this, BetaActivity.class);
startActivity(intent);
}
In BetaActivity.class i do something and then again i have a button where onClick acts like below:
public void addToDatabase() {
...
finish();
Intent intent = new Intent(this, AlphaActivity.class);
startActivity(intent);
}
When that codes executes, my app crashes and the error i get is on the AlphaActivity.class down there where i have p = snapshot.child("phone").getValue().toString(). I bet it has to do with the firebase method onDataChange but i can't figure it out. Any suggestion please ?
The error i get is:
06-04 16:59:16.885 13978-13978/com.example.johng.assosfood E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.johng.assosfood, PID: 13978
java.lang.NullPointerException
at com.example.johng.assosfood.ProfileActivity$1.onDataChange(ProfileActivity.java:48)
at com.google.android.gms.internal.firebase_database.zzfc.zza(Unknown Source)
at com.google.android.gms.internal.firebase_database.zzgx.zzdr(Unknown Source)
at com.google.android.gms.internal.firebase_database.zzhd.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5333)
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:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)
where ProfileActivity.java = AlphaActivity.java
I don't see any line looking like cDatabase = FireabseDatabase.getInstance().getReference();
phone child must contain value in numbers and you're retrieving it as a String
Instead of p = snapshot.child("phone").getValue().toString().
Always use p = snapshot.child("phone").getValue(String.class); or
p = String.valueOf(snapshot.child("phone").getValue(String.class)); do this for all snapshots.
Also in public void betaMethod(View view) use finish(); after startActivity() it's just good practice
When you starting a new activtiy your code is
public void betaMethod(View view) {
finish(); //here
Intent intent = new Intent(this, BetaActivity.class);
startActivity(intent);
}
Why you finish your activity when launching intent it means when you came back it can not find your last activity and in that case it can not load your last activity because it finished before launching intent. and if you want to remove backstack from activity then use
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
so remove finish from here and check your code works fine.
Let me know if it works for you.
Actually there is nothing wrong with calling finish() ! in fact if you go back and forth too many times without calling finish() this can cause an OOM exception as the stack fills up with instances of each activity. I think you just need to call the finish() method after startActivity() not before.
When you store long numbers in Firebase Database, it probably stores it in Float data type. So maybe to get value of "phone" you should try
String.valueOf((Float)snapshot.child("phone").getValue());
Related
I need to get an order id from Firestore and pass that id to my Query but I'm getting the order id happens asynchronously. So I am forced to initialize my adaptor inside the Firebase callback method. The issue is that my onStart and onStop methods are listening on the adaptor and then throws a NullPointException.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_to_cart);
// Navigate to men section
fromAddToCartToForHim = findViewById(R.id.fromAddToCartToForHim);
fromAddToCartToForHim.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(AddToCart.this, HimActivity.class);
startActivity(intent);
finish();
}
});
//Navigate to Women section
fromAddToCartToForHer = findViewById(R.id.fromAddToCartToForHer);
fromAddToCartToForHer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(AddToCart.this, WomenActivity.class);
startActivity(intent);
finish();
}
});
// Navigate to Household section
fromAddToCartToForHouseHold = findViewById(R.id.fromAddToCartToForHouseHold);
fromAddToCartToForHouseHold.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(AddToCart.this, HouseHoldActivity.class);
startActivity(intent);
finish();
}
});
// SetUpRecyclerView func
setUpRecycleView();
}
private void setUpRecycleView() {
// GET CURRENT ORDER ID
orderRef.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
#Override
public void onComplete(#NonNull #NotNull Task<QuerySnapshot> task) {
if (task.isComplete()) {
QuerySnapshot snapshot = task.getResult();
assert snapshot != null;
for (DocumentSnapshot snapshots : snapshot.getDocuments()) {
String user_id = snapshots.getString("user_id");
Boolean status = snapshots.getBoolean("status");
if (user_id.equals(getUserId()) && !status) {
// User has existing Order
// Check if order is pending or completed
String orderId = snapshots.getId();
Query query = orderRef
.document(orderId)
.collection("orderlist")
.orderBy("category").orderBy("priority", Query.Direction.ASCENDING);
FirestoreRecyclerOptions<OrderList> options = new FirestoreRecyclerOptions.Builder<OrderList>()
.setQuery(query, OrderList.class)
.build();
addToCartAdaptor = new AddToCartAdaptor(options);
recyclerView = findViewById(R.id.recyclerviewAddToCart);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(AddToCart.this));
recyclerView.setAdapter(addToCartAdaptor);
}
}
}
}
});
}
enter code here
#Override
protected void onStart() {
super.onStart();
addToCartAdaptor.startListening(); Error happens here
}
#Override
protected void onStop() { `enter code here`
super.onStop();
addToCartAdaptor.stopListening();
}
HERE IS THE ERROR I GET
W/example.neptun: Accessing hidden method Lcom/msic/qarth/PatchStore;->createDisableExceptionQarthFile(Ljava/lang/Throwable;)Z (blacklist, JNI)
E/example.neptun: [qarth_debug:] get PatchStore::createDisableExceptionQarthFile method fail.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.neptune, PID: 2884
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.example.neptune.Adapters.AddToCartAdaptor.startListening()' on a null object reference
at com.example.neptune.AddToCart.onStart(AddToCart.java:150)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1419)
at android.app.Activity.performStart(Activity.java:7479)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3454)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199)
at android.os.Handler.dispatchMessage(Handler.java:112)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
I/Process: Sending signal. PID: 2884 SIG: 9
When you are using the following line of code:
addToCartAdaptor = new AddToCartAdaptor(options);
Inside the "onComplete()" method, it means it will always run right after the onStart, as it takes some time to get the data from the orderRef reference. What you can do, is to create the (default) Query, FirestoreRecyclerOptions, and AddToCartAdaptor objects outside the onComplete() method, and once you get the data inside the callback, simply update the "options" object, with the data that you get from the database. In this way, you provide the data to the "options" object, only when it is available.
This also means that you'll never get a NullPointerException anymore because the addToCartAdaptor is already initialized.
I am getting this error when transtioning from a fragment to an activity as shown below:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference at android.content.ComponentName.<init>(ComponentName.java:130) at android.content.Intent.<init>(Intent.java:6108)
Below is my code for going to the next activity, The error occurs on the first line of the code below.
Intent mainIntent = new Intent (getContext(), MainActivity.class);
mainIntent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity (mainIntent);
I don't see any solution so far online.
It seems that you're getting a wrong context that raises this NullPointerException
Try to replace the below line:
Intent mainIntent = new Intent (getContext(), MainActivity.class);
With: >> if you're within an activity
Intent mainIntent = new Intent (this, MainActivity.class);
with: >> if you're within a callback listener within the activity
Intent mainIntent = new Intent (MyActivityName.this, MainActivity.class);
With: >> if you're within a fragment
Intent mainIntent = new Intent (requireActivity(), MainActivity.class);
Please try with getActivity() intsead of getContext()
I work the transaction of the fragment with this code
private Context context;
context.startActivity(new Intent(context, MainActivity.class));
I have been able to find a work around this. I realised I am getting the error because I am creating the new Intent inside the firebase OnCompleteListener as shown below. So after i removed it from inside the listener and called it outside, my program works properly.
I instead created a global boolean variable that I updated to true on successful data storage. Then I can access it somewhere else and then transtion to another if true.
#BEFORE
PostsRef.child(key).updateChildren(postsMap)
.addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(getActivity(), "New Post is updated successfully.", Toast.LENGTH_SHORT).show();
Intent mainIntent = new Intent (getActivity(), MainActivity.class);
mainIntent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity (mainIntent);
} else {
Toast.makeText(context, "Error occured while updating your post.", Toast.LENGTH_SHORT).show();
}
}
});
#AFTER
PostsRef.child(key).updateChildren(postsMap)
.addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
mSuccess = true;
Toast.makeText(getActivity(), "New Post is updated successfully.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "Error occured while updating your post.", Toast.LENGTH_SHORT).show();
}
}
});
Hello guys I have also realised one of the big causes of this error is the lifecycle methods.So I was overriding them inside my fragment to update the user state on the firebase database. Because of this they caused the android.content.Context.getPackageName() on a null object reference error whenever I tried to move to the main activity managing it. Incase I used the fragment transition to move to another fragment, the MainActivity would get excecuted more than twice. After stopping to override them my application worked properly. If someone would explain why that happens it would be great.
#Override
public void onStart() {
super.onStart();
updateUserState("Online");
}
#Override
public void onResume() {
super.onResume();
updateUserState("Online");
}
Since, you are calling from a Fragment, you should use getActivity() here instead of getContext()
Intent mainIntent = new Intent (getActivity(), MainActivity.class);
mainIntent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity (mainIntent);
This should help I hope.
Sometimes startActivity method throws an exception like:
Calling startActivity() from outside of an Activity context requires
the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
So you should intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) method
I am new to Android development and I am facing an issue in invoking an activity from a generic class where I have a reusable function.
I have MainActivity where I need to check if the application has Network connectivity and then check if the user is already signed in.
If the user is signed in I need to open the Rate activity otherwise I will open the Login activity.
I thought I can keep the logic that checks the Network connectivity and shows the popup reusable and move it to a Global class as below
public class Global extends AppCompatActivity {
public static boolean hasConnectivity = false;
public static boolean userSignedIn = false;
String TAG = "Debug Log - Helper";
Context context;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
context = this;
}
private void networkConnectionErrorDialog(final Context context, final Class targetClass){
Log.d(TAG, "Show Alert Dialog");
new AlertDialog.Builder(context)
.setTitle(R.string.connection_error_title)
.setMessage(R.string.connection_error_message)
.setIcon(R.drawable.warning)
.setPositiveButton(
R.string.try_again,
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Log.d(TAG, "Trying Again");
isNetworkAvailable(context, targetClass);
}
}).show();
}
protected void isNetworkAvailable(Context context, Class targetClass) {
if(NetworkUtil.isConnected(context)){
Log.d(TAG, "Has connectivity");
if(targetClass != null){
Log.d(TAG, targetClass.toString());
Intent targetIntent = new Intent(context, targetClass);
startActivity(targetIntent);
}
hasConnectivity = true;
return;
}else{
Log.d(TAG, "Has no connectivity");
hasConnectivity = false;
networkConnectionErrorDialog(context, targetClass);
}
}
}
I pass in the targetClass as Login.class or Rate.class (based on user signed in state) from the MainActivity where isNetworkAvailable() is invoked.
I am getting the following error. Could someone help me fix the issue and help me understand if my approach needs improvement?
java.lang.RuntimeException: Unable to resume activity {com.solitontech.dayatsoliton/com.solitontech.dayatsoliton.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3581)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3621)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2862)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference
at android.app.Activity.startActivityForResult(Activity.java:4488)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:4445)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4806)
at android.app.Activity.startActivity(Activity.java:4774)
at com.solitontech.dayatsoliton.Global.isNetworkAvailable(Global.java:50)
at com.solitontech.dayatsoliton.MainActivity.onResume(MainActivity.java:68)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1355)
at android.app.Activity.performResume(Activity.java:7117)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3556)
It looks like your application is experiencing a null pointer exception in your activity's onResume method. If you had called startActivityForResult, make sure that the data in
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{..}
is non null before processing it.
As for your question about starting an activity from your helper class Global, you can define a function like this.
private static void goToActivity(Context context, Class<?> activityClass){
Intent intent = new Intent(context, activityClass);
context.startActivity(intent);
}
You can call this method as below.
goToActivity(context,TargetActivity.class);
Good luck.
Intent targetIntent = new Intent(context, targetClass);
startActivity(targetIntent);
above code is wrong. You should pass your current activity and target activity here.
Intent intent = new Intent(CurrentActivity.this, TargetingActivity.class);
startActivity(intent);
As a example :
If you want to start ActivtyB form ActivtyA
Intent intent = new Intent(ActivityA.this, ActivityD.class);
startActivity(intent);
1st try to correct this error. then you can find some others.
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
I have my main Activity in which I have a few Buttons.
One of them is supposed to open the Camera.
To make it cleaner I am using View.onClick(), so I will just have the Button on the main Activity and the rest will be managed by another other class (Camactivity).
In my main Activity :
Button btnrep = (Button)findViewById(R.id.button3);
btnrep.setOnClickListener(new Camactivity(this));
and in my
public class Camactivity extends Activity implements View.OnClickListener
private File imageFile;
private Context appContext;
public MainActivity_1(Context context)
{
appContext = context;
}
#Override
public void onClick(View view) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);//use intent and pass in mediastore
//mediastore is a databases where image and video are stores and link
imageFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "BreedingGround.bmp");
/*link to a directory - pass in directory where you want to save the pictures and names of the file*/
Uri tempuri = Uri.fromFile(imageFile);//Convert imageFile to a Uri
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, tempuri);//location where u want the image file to be save after taking photo
intent.putExtra(android.provider.MediaStore.EXTRA_VIDEO_QUALITY, 1);//quality of out image, 1 means high quality image
startActivityForResult(intent, 0);//Request code 0 to identify who send the request
}
However I am getting a null pointer error at startActivityForResult(intent, 0);
FATAL EXCEPTION: main Process: com.example.mohit.softeng, PID: 22075
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
at android.content.ContextWrapper.getPackageManager(ContextWrapper.java:97)
at com.example.mohit.softeng.MainActivity_1.onClick(MainActivity_1.java:60)
at android.view.View.performClick(View.java:5697)
at android.widget.TextView.performClick(TextView.java:10826)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
You are more than welcome to define a View.OnClickListener subclass, but
there's really no reason I see to have Camactivity at all, so just implement View.OnClickListener onto MainActivity.
Besides, you will likely want the result from startActivityForResult within MainActivity's onActivityResult, not Camactivity.
So, with that suggestion
Button btnrep = (Button)findViewById(R.id.button3);
btnrep.setOnClickListener(this);
If you already have your Activity implementing an OnClickListener, then add an if-statement to check which button is clicked.
#Override
public void onClick(View view) {
switch (v.getId()) {
case R.id.button3:
openCamera();
}
}
private void openCamera() {
// That other code in Camactivity
}
Alternative answer... still not using new to make an Activity class.
Button btnrep = (Button)findViewById(R.id.button3);
btnrep.setOnClickListener(new View.onClickListener() {
#Override
public void onClick(View v) {
Intent cam = new Intent(MainActivity.this, Camactivity.class);
startActivityForResult(cam, 0); // If you need the result in MainAcivity, pass it back from camActivity
// else, just startActivity(cam);
}
});
Then, update Camactivity to start the camera intent as soon as it is created.
public class Camactivity extends Activity {
private File imageFile;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);//use intent and pass in mediastore
//mediastore is a databases where image and video are stores and link
imageFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "BreedingGround.bmp");
/*link to a directory - pass in directory where you want to save the pictures and names of the file*/
Uri tempuri = Uri.fromFile(imageFile);//Convert imageFile to a Uri
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, tempuri);//location where u want the image file to be save after taking photo
intent.putExtra(android.provider.MediaStore.EXTRA_VIDEO_QUALITY, 1);//quality of out image, 1 means high quality image
startActivityForResult(intent, 0);//Request code 0 to identify who send the request
}
#Override
public void onActivityResult (int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
// TODO: Handle camera intent result
}
}
}
I have two Activities
1. List view (multiple items each with title and link)
2. Text View( when click on any item in list view, fetches the link, do xml parsing and fetch the content and displayed)
I used intent to switch from List view to text view activity. Now on first time click, it start the text view activity. On pressing devices back button, it goes again to List view. Uptil now it's all right.
The main problem is that when the second time , i click on any item in List view, Android App gives me error of "Unfortunately application has stopped" .
and On clicking "OK" , it displayed the content of second item. and when second time , i pressed back button , application got closed
Here is my Second activity
public class ColoumnView extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_coloumn_view);
Intent intent = getIntent();
String message = intent.getStringExtra(MainListActivity.EXTRA_MESSAGE);
TextView myColoumnView = (TextView)findViewById(R.id.ColoumnView);
myColoumnView.setText(message);
}
#Override
public void onBackPressed()
{
// code here to show dialog
super.onBackPressed();
finish();
}
Here is the part of my first activity where it is creating an intent
protected void onPostExecute(List<ContentGetter.Content> contents) {
if (contents != null && mException == null) {
for(int i=0; i<contents.size();i++) {
if(contents.get(i).summary != null )
{
summaryContent= contents.get(i).summary;
}
else {
continue;
}
Intent intent = new Intent(MainListActivity.this,ColoumnView.class);
intent.putExtra(EXTRA_MESSAGE, summaryContent);
startActivity(intent);
Log.d(TAG, contents.get(i).summary != null ? contents.get(0).summary : "NULL");
}
} else {
if (mException instanceof IOException){
} else if (mException instanceof XmlPullParserException) {
}
}
}
Edit: Here is the crash Log
11-01 13:11:46.274 2296-2296/com.example.talha.appforblog E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.talha.appforblog, PID: 2296
java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.d(Log.java:139)
at com.example.talha.appforblog.MainListActivity$DownloadXmlTaskContent.onPostExecute(MainListActivity.java:241)
at com.example.talha.appforblog.MainListActivity$DownloadXmlTaskContent.onPostExecute(MainListActivity.java:206)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
The problem is in line no 241 of activity MainListActivity. You are calling a print there which is not having a proper msg to print for time being comment that line. If you share the line of code in that line that would help me narrow it down
Looks like this is doing it...
Log.d(TAG, contents.get(i).summary != null ? contents.get(0).summary : "NULL");
Ensure that your log message is not null, in this case, contents.get(0).summary.