• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Unfortunately ActiviyLifeCycle has stopped"

 
Muhammad Ammar Elahi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning ActivityLifeCycle from http://developer.android.com/training/basics/activity-lifecycle/stopping.html and getting message while running the code "Unfortunately ActiviyLifeCycle has stopped" and I want to know what is Notepad.Notes in values.put(Notepad.Notes.COLUMN_NAME_NOTE, getCurrentNoteText()); how to resolve this issue
Below is the code
**ActivityLifeCycle.java**

package com.example.activitylifecycle;

import android.content.ContentValues;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;
import android.content.Context;
import android.content.ClipData;



public class MainActivity extends ActionBarActivity {
TextView mTextView; //Member TextView
private Uri mUri;
private int mCurrentScore, mCurrentLevel;
static final String STATE_SCORE = "playerScore";
static final String STATE_LEVEL = "playerLevel";
/*private static final int COLUMN_NAME_NOTE=0;
private static final int COLUMN_NAME_TITLE=1;*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// Save the user's current game state
savedInstanceState.putInt(STATE_SCORE, mCurrentScore);
savedInstanceState.putInt(STATE_LEVEL, mCurrentLevel);

// Always call the superclass so it can save the view hierarchy state
super.onSaveInstanceState(savedInstanceState);
super.onCreate(savedInstanceState);

// Check whether we're recreating a previously destroyed instance
if (savedInstanceState != null) {
// Restore value of members from saved state
mCurrentScore = savedInstanceState.getInt(STATE_SCORE);
mCurrentLevel = savedInstanceState.getInt(STATE_LEVEL);
} else {
// Probably initialize members with default values for a new instance
}
// Set the user interface layout for this Activity
// The layout file is defined in the project res/layout/main_activity.xml file
setContentView(R.layout.activity_main);

// Initialize member TextView so we can manipulate it later
mTextView = (TextView) findViewById(R.id.text_message);

// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// For the main activity, make sure the icon in the action bar
// does not behave as a button
android.app.ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(false);
}
}
public void OnRestoreInstanceState(Bundle savedInstanceState){
//Always call the superclass so it can restore the vie hierarchy
super.onRestoreInstanceState(savedInstanceState);

//Restore state members for state instance
mCurrentScore = savedInstanceState.getInt(STATE_SCORE);
mCurrentLevel = savedInstanceState.getInt(STATE_LEVEL);

}
@Override
public void onDestroy() {
super.onDestroy(); // Always call the superclass

// Stop method tracing that the activity started during onCreate()
android.os.Debug.stopMethodTracing();
}

@Override
protected void onStop(){
super.onStop(); //Always call superclass method 1st

//Save note current draft and we want to be sure current note's progress isn't lost
ContentValues values = new ContentValues();
values.put(Notepad.Notes.COLUMN_NAME_NOTE, getCurrentNoteText());
values.put(Notepad.Notes.COLUMN_NAME_TITLE, getCurrentNoteTitle());

getContentResolver().update(
mUri, // Uri for the Note to Update
values, // The map of column name and new values apply to them
null, // No select criteria are used
null // No where column are used
);
}

@Override
protected void onStart() {
super.onStart(); // Always call the superclass method first

// The activity is either being restarted or started for the first time
// so this is where we should make sure that GPS is enabled
LocationManager locationManager =
(LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

if (!gpsEnabled) {
// Create a dialog here that requests the user to enable GPS, and use an intent
// with the android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS action
// to take the user to the Settings screen to enable GPS when they click "OK"
}
}

@Override
protected void onRestart() {
super.onRestart(); // Always call the superclass method first

// Activity being restarted from stopped state
}
}

**Notepad.java**

package com.example.activitylifecycle;

public class Notepad {
public class Notes {
public static final String COLUMN_NAME_NOTE = "note";
public static final String COLUMN_NAME_TITLE = "title";
}
}
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you send LogCat outputs.
Oh. Please edit your post and put your code into code tag.
 
Muhammad Ammar Elahi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Could you please tell me what is Notepad.Notes is it something class values.put(Notepad.Notes.COLUMN_NAME_TITLE, getCurrentNoteTitle()); ?


Logcats

12-25 19:20:57.230: E/AndroidRuntime(623): at java.lang.reflect.Method.invokeNative(Native Method)
12-25 19:20:57.230: E/AndroidRuntime(623): at java.lang.reflect.Method.invoke(Method.java:511)
12-25 19:20:57.230: E/AndroidRuntime(623): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-25 19:20:57.230: E/AndroidRuntime(623): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-25 19:20:57.230: E/AndroidRuntime(623): at dalvik.system.NativeStart.main(Native Method)
12-25 19:20:57.230: E/AndroidRuntime(623): Caused by: java.lang.NullPointerException
12-25 19:20:57.230: E/AndroidRuntime(623): at com.example.activitylifecycle.MainActivity.onCreate(MainActivity.java:25)
12-25 19:20:57.230: E/AndroidRuntime(623): at android.app.Activity.performCreate(Activity.java:5008)
12-25 19:20:57.230: E/AndroidRuntime(623): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-25 19:20:57.230: E/AndroidRuntime(623): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am guessing you are missing some point.
You are saving something without creating it.

if you look at your code. You are trying to save instance before calling super.onCreate.

I think you should change your code as follows.
Of course this is first thing came up my mind and i am sure someone in here help you better.

 
Muhammad Ammar Elahi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brother it is still showing me this error kindly check this i am follow this tutorial developer.android.com
 
Muhammad Ammar Elahi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This issue i am facing what actually is


The below class is right?

**Notepad.java**

package com.example.activitylifecycle;

public class Notepad {
public class Notes {
public static final String COLUMN_NAME_NOTE = "note";
public static final String COLUMN_NAME_TITLE = "title";
}
}
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no problem with NotePad class. I think when you change your code as i suggested your problem will be solve.
 
Muhammad Ammar Elahi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did but still getting same error
 
Muhammad Ammar Elahi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to hear that.
That's all i can do for now. I am pretty sure Ulf can help you better. When he became online definitely will answer you.
 
Muhammad Ammar Elahi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks for giving your time
 
Rehan Zahoor
Ranch Hand
Posts: 83
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems that savedInstanceState is null. You should notice that you are checking it against null value on line 25 and you have removed
super.onSaveInstanceState(savedInstanceState)
from your new code. Add that line in start of method.
You can check your variable values by printing them in logcat.
 
Muhammad Ammar Elahi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok i will check it and let you know about that
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic