Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2
This is the forum to discuss the Wrox book Professional Android Application Development by Reto Meier; ISBN: 9780470344712
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 2nd, 2012, 05:52 AM
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default chapter 7, earthquake, NullPointer Exception

Hi,
I have tried the Earthquake example in chapter 7 of this book...
And i'm getting Null Pointer Exception when i run in emulator..

This happens after i updated the code as in "USING THE PROVIDER" in page no. "236"..

Logcat shows as follows:
Quote:
02-02 15:12:12.219: E/ActivityThread(1154): Failed to find provider info for com.paad.provider.earthquake
02-02 15:12:12.219: D/AndroidRuntime(1154): Shutting down VM
02-02 15:12:12.231: W/dalvikvm(1154): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
02-02 15:12:12.301: E/AndroidRuntime(1154): FATAL EXCEPTION: main
02-02 15:12:12.301: E/AndroidRuntime(1154): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.quake/com.android.quake.Earthquake}: java.lang.NullPointerException
02-02 15:12:12.301: E/AndroidRuntime(1154): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:1956)
02-02 15:12:12.301: E/AndroidRuntime(1154): at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:1981)
02-02 15:12:12.301: E/AndroidRuntime(1154): at android.app.ActivityThread.access$600(ActivityThre ad.java:123)
02-02 15:12:12.301: E/AndroidRuntime(1154): at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1147)
02-02 15:12:12.301: E/AndroidRuntime(1154): at android.os.Handler.dispatchMessage(Handler.java:99 )
02-02 15:12:12.301: E/AndroidRuntime(1154): at android.os.Looper.loop(Looper.java:137)
02-02 15:12:12.301: E/AndroidRuntime(1154): at android.app.ActivityThread.main(ActivityThread.jav a:4424)
02-02 15:12:12.301: E/AndroidRuntime(1154): at java.lang.reflect.Method.invokeNative(Native Method)
02-02 15:12:12.301: E/AndroidRuntime(1154): at java.lang.reflect.Method.invoke(Method.java:511)
02-02 15:12:12.301: E/AndroidRuntime(1154): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:784)
02-02 15:12:12.301: E/AndroidRuntime(1154): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:551)
02-02 15:12:12.301: E/AndroidRuntime(1154): at dalvik.system.NativeStart.main(Native Method)
02-02 15:12:12.301: E/AndroidRuntime(1154):Caused by: java.lang.NullPointerException
02-02 15:12:12.301: E/AndroidRuntime(1154): at com.android.quake.Earthquake.loadQuakesFromProvide r(Earthquake.java:201)
02-02 15:12:12.301: E/AndroidRuntime(1154): at com.android.quake.Earthquake.onCreate(Earthquake.j ava:78)
02-02 15:12:12.301: E/AndroidRuntime(1154): at android.app.Activity.performCreate(Activity.java:4 465)
02-02 15:12:12.301: E/AndroidRuntime(1154): at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1049)
02-02 15:12:12.301: E/AndroidRuntime(1154): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:1920)
02-02 15:12:12.301: E/AndroidRuntime(1154): ... 11 more
Can any one plz help me with this...

Regards,
Mounika
Reply With Quote
  #2 (permalink)  
Old February 2nd, 2012, 06:21 AM
Authorized User
Points: 62, Level: 1
Points: 62, Level: 1 Points: 62, Level: 1 Points: 62, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2010
Posts: 12
Thanks: 0
Thanked 3 Times in 2 Posts
Default

The error is being caused by something not being set at line 201 in Earthquake.java. Are you sure that you have entered all of the code exactly as in the book. if you post your code I may be able to spot the problem for you.
Reply With Quote
The Following User Says Thank You to aajshaw For This Useful Post:
Mounika (February 2nd, 2012)
  #3 (permalink)  
Old February 2nd, 2012, 07:17 AM
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi,

Thanks for ur quick reply..

My code is as follows..

Earthquake.java
Code:
package com.android.quake;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.database.Cursor;
import android.location.Location;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class Earthquake extends Activity implements
		OnSharedPreferenceChangeListener {

	ListView earthquakeListView;
	ArrayAdapter<Quake> aa;
	ArrayList<Quake> earthquakes = new ArrayList<Quake>();
	static final private int QUAKE_DIALOG = 1;
	Quake selectedQuake;
	static final private int MENU_PREFERENCES = Menu.FIRST + 1;
	private static final int SHOW_PREFERENCES = 1;
	int minimumMagnitude = 0;
	boolean autoUpdate = false;
	int updateFreq = 0;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		earthquakeListView = (ListView) this
				.findViewById(R.id.earthquakeListView);
		earthquakeListView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView _av, View _v, int _index,
					long arg3) {
				selectedQuake = earthquakes.get(_index);
				showDialog(QUAKE_DIALOG);
			}
		});
		int layoutID = android.R.layout.simple_list_item_1;
		aa = new ArrayAdapter<Quake>(this, layoutID, earthquakes);
		earthquakeListView.setAdapter(aa);
		loadQuakesFromProvider();
		updateFromPreferences();
		refreshEarthquakes();
	}

	private void refreshEarthquakes() {
		// Get the XML
		URL url;
		try {
			String quakeFeed = getString(R.string.quake_feed);
			url = new URL(quakeFeed);
			URLConnection connection;
			connection = url.openConnection();
			HttpURLConnection httpConnection = (HttpURLConnection) connection;
			int responseCode = httpConnection.getResponseCode();
			if (responseCode == HttpURLConnection.HTTP_OK) {
				InputStream in = httpConnection.getInputStream();
				DocumentBuilderFactory dbf = DocumentBuilderFactory
						.newInstance();
				DocumentBuilder db = dbf.newDocumentBuilder();
				// Parse the earthquake feed.
				Document dom = db.parse(in);
				Element docEle = dom.getDocumentElement();
				// Clear the old earthquakes
				earthquakes.clear();
				loadQuakesFromProvider();
				// Get a list of each earthquake entry.
				NodeList nl = docEle.getElementsByTagName("entry");
				if (nl != null && nl.getLength() > 0) {
					for (int i = 0; i < nl.getLength(); i++) {
						Element entry = (Element) nl.item(i);
						Element title = (Element) entry.getElementsByTagName(
								"title").item(0);
						Element g = (Element) entry.getElementsByTagName(
								"georss:point").item(0);
						Element when = (Element) entry.getElementsByTagName(
								"updated").item(0);
						Element link = (Element) entry.getElementsByTagName(
								"link").item(0);
						String details = title.getFirstChild().getNodeValue();
						String hostname = "http://earthquake.usgs.gov";
						String linkString = hostname
								+ link.getAttribute("href");
						String point = g.getFirstChild().getNodeValue();
						String dt = when.getFirstChild().getNodeValue();
						SimpleDateFormat sdf = new SimpleDateFormat(
								"dd-MM-yyyy HH:mm:ss");
						Date qdate = new GregorianCalendar(0, 0, 0).getTime();
						try {
							qdate = sdf.parse(dt);
						} catch (ParseException e) {
							e.printStackTrace();
						}
						String[] location = point.split(" ");
						Location l = new Location("dummyGPS");
						l.setLatitude(Double.parseDouble(location[0]));
						l.setLongitude(Double.parseDouble(location[1]));
						String magnitudeString = details.split(" ")[1];
						int end = magnitudeString.length() - 1;
						double magnitude = Double.parseDouble(magnitudeString
								.substring(0, end));
						details = details.split(",")[1].trim();
						Quake quake = new Quake(qdate, details, l, magnitude,
								linkString);
						// Process a newly found earthquake
						addNewQuake(quake);
					}
				}
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		} catch (SAXException e) {
			e.printStackTrace();
		} finally {
		}
	}

	private void addNewQuake(Quake _quake) {

		ContentResolver cr = getContentResolver();
		// Construct a where clause to make sure we don’t already have this
		// earthquake in the provider.
		String w = EarthquakeProvider.KEY_DATE + " = "
				+ _quake.getDate().getTime();
		Cursor c = cr.query(EarthquakeProvider.CONTENT_URI, null, w, null, null);
		// If the earthquake is new, insert it into the provider.
		if (c.getCount() == 0) {
			ContentValues values = new ContentValues();
			values.put(EarthquakeProvider.KEY_DATE, _quake.getDate().getTime());
			values.put(EarthquakeProvider.KEY_DETAILS, _quake.getDetails());
			double lat = _quake.getLocation().getLatitude();
			double lng = _quake.getLocation().getLongitude();
			values.put(EarthquakeProvider.KEY_LOCATION_LAT, lat);
			values.put(EarthquakeProvider.KEY_LOCATION_LNG, lng);
			values.put(EarthquakeProvider.KEY_LINK, _quake.getLink());
			values.put(EarthquakeProvider.KEY_MAGNITUDE, _quake.getMagnitude());
			cr.insert(EarthquakeProvider.CONTENT_URI, values);
			earthquakes.add(_quake);
			addQuakeToArray(_quake);
		}
		c.close();
	}

	private void addQuakeToArray(Quake _quake) {
		if (_quake.getMagnitude() > minimumMagnitude) {
			// Add the new quake to our list of earthquakes.
			earthquakes.add(_quake);
			// Notify the array adapter of a change.
			aa.notifyDataSetChanged();
		}
	}

	private void loadQuakesFromProvider() {
		// Clear the existing earthquake array
		earthquakes.clear();
		ContentResolver cr = getContentResolver();
		// Return all the saved earthquakes
		Cursor c = cr.query(EarthquakeProvider.CONTENT_URI, null, null, null,
				null);
		if (c.moveToFirst()) {
			do {
				// Extract the quake details.
				Long datems = c.getLong(EarthquakeProvider.DATE_COLUMN);
				String details = c.getString(EarthquakeProvider.DETAILS_COLUMN);
				Float lat = c.getFloat(EarthquakeProvider.LATITUDE_COLUMN);
				Float lng = c.getFloat(EarthquakeProvider.LONGITUDE_COLUMN);
				Double mag = c.getDouble(EarthquakeProvider.MAGNITUDE_COLUMN);
				String link = c.getString(EarthquakeProvider.LINK_COLUMN);
				Location location = new Location("dummy");
				location.setLongitude(lng);
				location.setLatitude(lat);
				Date date = new Date(datems);
				Quake q = new Quake(date, details, location, mag, link);
				addQuakeToArray(q);
			} while (c.moveToNext());
		}		
	}

	static final private int MENU_UPDATE = Menu.FIRST;

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu.add(0, MENU_UPDATE, Menu.NONE, R.string.menu_update);
		menu.add(0, MENU_PREFERENCES, Menu.NONE, R.string.menu_preferences);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		super.onOptionsItemSelected(item);
		switch (item.getItemId()) {
		case (MENU_UPDATE): {
			refreshEarthquakes();
			return true;
		}
		case (MENU_PREFERENCES): {
			Intent i = new Intent(this, Preferences.class);
			startActivity(i);
			return true;
		}
		}
		return false;
	}

	@Override
	public Dialog onCreateDialog(int id) {
		switch (id) {
		case (QUAKE_DIALOG):
			LayoutInflater li = LayoutInflater.from(this);
			View quakeDetailsView = li.inflate(R.layout.quake_details, null);
			AlertDialog.Builder quakeDialog = new AlertDialog.Builder(this);
			quakeDialog.setTitle("Quake Time");
			quakeDialog.setView(quakeDetailsView);
			return quakeDialog.create();
		}
		return null;
	}

	@Override
	public void onPrepareDialog(int id, Dialog dialog) {
		switch (id) {
		case (QUAKE_DIALOG):
			SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
			String dateString = sdf.format(selectedQuake.getDate());
			String quakeText = "Magnitude " + selectedQuake.getMagnitude()
					+ "\n" + selectedQuake.getDetails() + "\n"
					+ selectedQuake.getLink();
			AlertDialog quakeDialog = (AlertDialog) dialog;
			quakeDialog.setTitle(dateString);
			TextView tv = (TextView) quakeDialog
					.findViewById(R.id.quakeDetailsTextView);
			tv.setText(quakeText);
			break;
		}
	}

	// private void updateFromPreferences() {
	// Context context = getApplicationContext();
	// SharedPreferences prefs = PreferenceManager
	// .getDefaultSharedPreferences(context);
	// int minMagIndex = Integer.parseInt(prefs.getString(
	// Preferences.PREF_MIN_MAG, "0"));
	// // int minMagIndex = prefs.getInt(Preferences.PREF_MIN_MAG, 0);
	// if (minMagIndex < 0)
	// minMagIndex = 0;
	// int freqIndex = Integer.parseInt(prefs.getString(
	// Preferences.PREF_UPDATE_FREQ, "0"));
	// // int freqIndex = prefs.getInt(Preferences.PREF_UPDATE_FREQ, 0);
	// if (freqIndex < 0)
	// freqIndex = 0;
	// autoUpdate = prefs.getBoolean(Preferences.PREF_AUTO_UPDATE, false);
	// Resources r = getResources();
	// // Get the option values from the arrays.
	// // int[] minMagValues = r.getIntArray(R.array.magnitude);
	// int[] freqValues = r.getIntArray(R.array.update_freq_values);
	// // Convert the values to ints.
	// // minimumMagnitude = minMagValues[minMagIndex];
	// minimumMagnitude = Integer.parseInt(prefs.getString(
	// Preferences.PREF_MIN_MAG, "0"));
	// updateFreq = freqValues[freqIndex];
	// }

	private void updateFromPreferences() {
		final SharedPreferences preferences = PreferenceManager
				.getDefaultSharedPreferences(getApplicationContext());

		autoUpdate = preferences
				.getBoolean(Preferences.PREF_AUTO_UPDATE, false);
		minimumMagnitude = Integer.parseInt(preferences.getString(
				Preferences.PREF_MIN_MAG, "3"));
		updateFreq = Integer.parseInt(preferences.getString(
				Preferences.PREF_UPDATE_FREQ, "60"));
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (requestCode == SHOW_PREFERENCES) {
			updateFromPreferences();
			refreshEarthquakes();
		}
	}

	@Override
	public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
		updateFromPreferences();
		refreshEarthquakes();
	}
}
EarthquakeProvider.java
Code:
package com.android.quake;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;

public class EarthquakeProvider extends ContentProvider {

	public static final Uri CONTENT_URI = Uri
			.parse("content://com.android.provider.quake/earthquakes");

	private SQLiteDatabase earthquakeDB;
	private static final String TAG = "EarthquakeProvider";
	private static final String DATABASE_NAME = "earthquakes.db";
	private static final int DATABASE_VERSION = 1;
	private static final String EARTHQUAKE_TABLE = "earthquakes";
	
	// Column Names
	public static final String KEY_ID = "_id";
	public static final String KEY_DATE = "date";
	public static final String KEY_DETAILS = "details";
	public static final String KEY_LOCATION_LAT = "latitude";
	public static final String KEY_LOCATION_LNG = "longitude";
	public static final String KEY_MAGNITUDE = "magnitude";
	public static final String KEY_LINK = "link";
	
	// Column indexes
	public static final int DATE_COLUMN = 1;
	public static final int DETAILS_COLUMN = 2;
	public static final int LONGITUDE_COLUMN = 3;
	public static final int LATITUDE_COLUMN = 4;
	public static final int MAGNITUDE_COLUMN = 5;
	public static final int LINK_COLUMN = 6;

	// Create the constants used to differentiate between the different URI
	// requests.
	private static final int QUAKES = 1;
	private static final int QUAKE_ID = 2;
	private static final UriMatcher uriMatcher;
	// Allocate the UriMatcher object, where a URI ending in ‘earthquakes’ will
	// correspond to a request for all earthquakes, and ‘earthquakes’ with a
	// trailing ‘/[rowID]’ will represent a single earthquake row.
	static {
		uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
		uriMatcher
				.addURI("com.android.provider.quake", "earthquakes", QUAKES);
		uriMatcher.addURI("com.android.provider.quake", "earthquakes/#",
				QUAKE_ID);
	}

	@Override
	public boolean onCreate() {
		Context context = getContext();
		earthquakeDatabaseHelper dbHelper = new earthquakeDatabaseHelper(
				context, DATABASE_NAME, null, DATABASE_VERSION);
		earthquakeDB = dbHelper.getWritableDatabase();
		return (earthquakeDB == null) ? false : true;
	}

	@Override
	public String getType(Uri uri) {
		switch (uriMatcher.match(uri)) {
		case QUAKES:
			return "vnd.android.cursor.dir/vnd.android.earthquake";
		case QUAKE_ID:
			return "vnd.android.cursor.item/vnd.android.earthquake";
		default:
			throw new IllegalArgumentException("Unsupported URI: " + uri);
		}
	}

	@Override
	public Cursor query(Uri uri, String[] projection, String selection,
			String[] selectionArgs, String sort) {
		SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
		qb.setTables(EARTHQUAKE_TABLE);
		// If this is a row query, limit the result set to the passed in row.
		switch (uriMatcher.match(uri)) {
		case QUAKE_ID:
			qb.appendWhere(KEY_ID + "=" + uri.getPathSegments().get(1));
			break;
		default:
			break;
		}
		// If no sort order is specified sort by date / time
		String orderBy;
		if (TextUtils.isEmpty(sort)) {
			orderBy = KEY_DATE;
		} else {
			orderBy = sort;
		}
		// Apply the query to the underlying database.
		Cursor c = qb.query(earthquakeDB, projection, selection, selectionArgs,
				null, null, orderBy);
		// Register the contexts ContentResolver to be notified if
		// the cursor result set changes.
		c.setNotificationUri(getContext().getContentResolver(), uri);
		// Return a cursor to the query result.
		return c;
	}

	@Override
	public Uri insert(Uri _uri, ContentValues _initialValues) {
		// Insert the new row, will return the row number if
		// successful.
		long rowID = earthquakeDB.insert(EARTHQUAKE_TABLE, "quake",
				_initialValues);
		// Return a URI to the newly inserted row on success.
		if (rowID > 0) {
			Uri uri = ContentUris.withAppendedId(CONTENT_URI, rowID);
			getContext().getContentResolver().notifyChange(uri, null);
			return uri;
		}
		throw new SQLException("Failed to insert row into " + _uri);
	}

	@Override
	public int delete(Uri uri, String where, String[] whereArgs) {
		int count;
		switch (uriMatcher.match(uri)) {
		case QUAKES:
			count = earthquakeDB.delete(EARTHQUAKE_TABLE, where, whereArgs);
			break;
		case QUAKE_ID:
			String segment = uri.getPathSegments().get(1);
			count = earthquakeDB.delete(EARTHQUAKE_TABLE,
					KEY_ID
							+ "="
							+ segment
							+ (!TextUtils.isEmpty(where) ? " AND (" + where
									+ ')' : ""), whereArgs);
			break;
		default:
			throw new IllegalArgumentException("Unsupported URI: " + uri);
		}
		getContext().getContentResolver().notifyChange(uri, null);
		return count;
	}

	@Override
	public int update(Uri uri, ContentValues values, String where,
			String[] whereArgs) {
		int count;
		switch (uriMatcher.match(uri)) {
		case QUAKES:
			count = earthquakeDB.update(EARTHQUAKE_TABLE, values, where,
					whereArgs);
			break;
		case QUAKE_ID:
			String segment = uri.getPathSegments().get(1);
			count = earthquakeDB.update(EARTHQUAKE_TABLE, values,
					KEY_ID
							+ "="
							+ segment
							+ (!TextUtils.isEmpty(where) ? " AND (" + where
									+ ')' : ""), whereArgs);
			break;
		default:
			throw new IllegalArgumentException("Unknown URI " + uri);
		}
		getContext().getContentResolver().notifyChange(uri, null);
		return count;
	}

	// Helper class for opening, creating, and managing database version control
	private static class earthquakeDatabaseHelper extends SQLiteOpenHelper {
		private static final String DATABASE_CREATE = "create table "
				+ EARTHQUAKE_TABLE + " (" + KEY_ID
				+ " integer primary key autoincrement, " + KEY_DATE
				+ " INTEGER, " + KEY_DETAILS + " TEXT, " + KEY_LOCATION_LAT
				+ " FLOAT, " + KEY_LOCATION_LNG + " FLOAT, " + KEY_MAGNITUDE
				+ " FLOAT, " + KEY_LINK + " TEXT);";

		public earthquakeDatabaseHelper(Context context, String name,
				CursorFactory factory, int version) {
			super(context, name, factory, version);
		}

		@Override
		public void onCreate(SQLiteDatabase db) {
			db.execSQL(DATABASE_CREATE);
		}

		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
					+ newVersion + ", which will destroy all old data");
			db.execSQL("DROP TABLE IF EXISTS " + EARTHQUAKE_TABLE);
			onCreate(db);
		}
	}
}
manifest.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.quake"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".Earthquake"
            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=".Preferences"
            android:label="Earthquake Preferences" >
        </activity>
    </application>

    <provider
        android:name=".EarthquakeProvider"
        android:authorities="com.android.provider.quake" />

</manifest>
Plz let me know if u still need some info for solving this..

Waitiing for reply...

Regards,
Mounika
Reply With Quote
  #4 (permalink)  
Old February 2nd, 2012, 08:52 AM
Authorized User
Points: 62, Level: 1
Points: 62, Level: 1 Points: 62, Level: 1 Points: 62, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2010
Posts: 12
Thanks: 0
Thanked 3 Times in 2 Posts
Default

The problem is that the Cursor variable 'c' is a null. The variable should be allocated a Cursor by the call at line 199 of Earthquake.java so I suspect there is something wrong in your EarthquakeProvider class. At this stage I would go through EarthquakeProvider.java and make sure all of the strings that are set in there point to the right things, they are different from the source code that I have on my system. Worst case would be to download the source code for the book and compare it with yours.

Hope that helps.
Reply With Quote
  #5 (permalink)  
Old February 3rd, 2012, 03:09 AM
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi,

Thanks for ur suggestion..
The code which i download from this forum works fine..
but what i'm running before is not working..:(

The only diff is i have changed the package name and one more thing is in manifest the provider's authorities also i have changed..


But till now dint get what is the actual error / prob in my code which i have posted..

Regards,
Mounika
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 7 Earthquake 2, Earthquake.java, error onActivityResult dbomberg BOOK: Professional Android 2 Application Development 2 November 30th, 2012 05:52 AM
Please help: Chapter 9 Earthquake 4 dahe BOOK: Professional Android 2 Application Development 0 July 21st, 2010 04:41 PM
Socket exception in Chp 6 earthquake example ailling BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 0 June 24th, 2010 08:13 PM
Chapter 7 Part 2 Earthquake Exception clombardo BOOK: Professional Android 2 Application Development 3 April 29th, 2010 11:46 AM
Getting Exception after the Correction -for Chapter 6 Part 2 Earthquake project clombardo BOOK: Professional Android 2 Application Development 1 April 26th, 2010 07:03 AM



All times are GMT -4. The time now is 03:14 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.