Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9327991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T05:28:25+00:00 2026-06-19T05:28:25+00:00

i have try with commonsware sample here is the activity public class ConstantsBrowser extends

  • 0

i have try with commonsware sample

here is the activity

public class ConstantsBrowser extends ListActivity {
  private LocationManager lm;
  private LocationListener locListener;
  private TextView latTxt, lonTxt;
  private double dLat=0;
  private double dLon=0;
  Intent intent = null;
  private static final int ADD_ID = Menu.FIRST+1;
  private static final int DELETE_ID = Menu.FIRST+3;
  private static final int UPDATE_ID = Menu.FIRST+4;
  public static final int SHOW_SUB_ACTIVITY_VIEW=3;
  private DatabaseHelper db=null;
  private Cursor constantsCursor=null;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.banner);

    latTxt = (TextView) findViewById(R.id.latitudeTxt);
    lonTxt = (TextView) findViewById(R.id.longitudeTxt);

    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locListener = new MyLocationListener();
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10, 10,locListener);

    db=new DatabaseHelper(this);
    constantsCursor=db
                      .getReadableDatabase()
                      .rawQuery("SELECT _ID, title, value "+
                                "FROM constants ORDER BY _ID",
                                null);

    ListAdapter adapter=new SimpleCursorAdapter(this,
                          R.layout.row, constantsCursor,
                          new String[] {
                                        DatabaseHelper.ID,
                                        DatabaseHelper.TITLE,
                                        DatabaseHelper.VALUE},
                          new int[] {R.id.id, R.id.alamat, R.id.value});

    setListAdapter(adapter);
    registerForContextMenu(getListView());
  }

  @Override
  public void onDestroy() {
    super.onDestroy();

    constantsCursor.close();
    db.close();
  }

  private class MyLocationListener implements LocationListener {
        @Override
        public void onLocationChanged(Location loc) {
            // TODO Auto-generated method stub
            if (loc != null) {
                latTxt.setText(String.valueOf(loc.getLatitude()));
                lonTxt.setText(String.valueOf(loc.getLongitude()));
            }
        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }

    }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(Menu.NONE, ADD_ID, Menu.NONE, "Data Baru")
        .setIcon(R.drawable.add)
        .setAlphabeticShortcut('a');

    return(super.onCreateOptionsMenu(menu));
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case ADD_ID:
        add();
        return(true);
    }

    return(super.onOptionsItemSelected(item));
  }

  @Override
  public void onCreateContextMenu(ContextMenu menu, View v,
                                    ContextMenu.ContextMenuInfo menuInfo) {
    menu.add(Menu.NONE, DELETE_ID, Menu.NONE, "Delete");
    menu.add(Menu.NONE, UPDATE_ID, Menu.NONE, "Update")
        .setAlphabeticShortcut('d');
  }

  @Override
  public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case DELETE_ID:
        AdapterView.AdapterContextMenuInfo info=
          (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();

        delete(info.id);
        return(true);

      case UPDATE_ID:
          intent = new Intent(ConstantsBrowser.this, MainActivity.class);
            startActivityForResult(intent, SHOW_SUB_ACTIVITY_VIEW);
          return(true);
    }

    return(super.onOptionsItemSelected(item));
  }

  private void add() {
    LayoutInflater inflater=LayoutInflater.from(this);
    View addView=inflater.inflate(R.layout.add_edit, null);
    final DialogWrapper wrapper=new DialogWrapper(addView);

    new AlertDialog.Builder(this)
      .setTitle(R.string.add_title)
      .setView(addView)
      .setPositiveButton(R.string.ok,
                          new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,
                              int whichButton) {
          processAdd(wrapper);
        }
      })
      .setNegativeButton(R.string.cancel,
                          new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,
                              int whichButton) {
          // ignore, just dismiss
        }
      })
      .show();
  }

  private void delete(final long rowId) {
    if (rowId>0) {
      new AlertDialog.Builder(this)
        .setTitle(R.string.delete_title)
        .setPositiveButton(R.string.ok,
                            new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog,
                                int whichButton) {
            processDelete(rowId);
          }
        })
        .setNegativeButton(R.string.cancel,
                            new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog,
                                int whichButton) {
          // ignore, just dismiss
          }
        })
        .show();
    }
  }

  private void processAdd(DialogWrapper wrapper) {
    ContentValues values=new ContentValues(2);

    values.put(DatabaseHelper.TITLE, wrapper.getTitle());
    values.put(DatabaseHelper.VALUE, wrapper.getValue());

    db.getWritableDatabase().insert("constants", DatabaseHelper.TITLE, values);
    constantsCursor.requery();
  }

  private void processDelete(long rowId) {
    String[] args={String.valueOf(rowId)};

    db.getWritableDatabase().delete("constants", "_ID=?", args);
    constantsCursor.requery();
  }

  class DialogWrapper {
    EditText titleField=null;
    EditText valueField=null;
    View base=null;

    DialogWrapper(View base) {
      this.base=base;
      valueField=(EditText)base.findViewById(R.id.value);
    }

    String getTitle() {
      return(getTitleField().getText().toString());
    }

    String getValue() {
      return(getValueField().getText().toString());
    }

    private EditText getTitleField() {
      if (titleField==null) {
        titleField=(EditText)base.findViewById(R.id.title);
      }

      return(titleField);
    }

    private EditText getValueField() {
      if (valueField==null) {
        valueField=(EditText)base.findViewById(R.id.value);
      }

      return(valueField);
    }
  }
}

i add gps in this activity but when i try the app is force close

here is the manifest

i add a permission

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >
    </uses-permission>
    <uses-permission android:name="android.permission.INTERNET" >
    </uses-permission>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >
    </uses-permission>
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.CAMERA" >

and
here is the logcat nullpointer exception

02-20 12:07:32.203: ERROR/AndroidRuntime(8904): FATAL EXCEPTION: main
02-20 12:07:32.203: ERROR/AndroidRuntime(8904): java.lang.NullPointerException
02-20 12:07:32.203: ERROR/AndroidRuntime(8904):     at com.commonsware.android.constants.ConstantsBrowser$MyLocationListener.onLocationChanged(ConstantsBrowser.java:98)
02-20 12:07:32.203: ERROR/AndroidRuntime(8904):     at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:227)
02-20 12:07:32.203: ERROR/AndroidRuntime(8904):     at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:160)
02-20 12:07:32.203: ERROR/AndroidRuntime(8904):     at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:176)
02-20 12:07:32.203: ERROR/AndroidRuntime(8904):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-20 12:07:32.203: ERROR/AndroidRuntime(8904):     at android.os.Looper.loop(Looper.java:130)
02-20 12:07:32.203: ERROR/AndroidRuntime(8904):     at android.app.ActivityThread.main(ActivityThread.java:3683)
02-20 12:07:32.203: ERROR/AndroidRuntime(8904):     at java.lang.reflect.Method.invokeNative(Native Method)
02-20 12:07:32.203: ERROR/AndroidRuntime(8904):     at java.lang.reflect.Method.invoke(Method.java:507)
02-20 12:07:32.203: ERROR/AndroidRuntime(8904):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-20 12:07:32.203: ERROR/AndroidRuntime(8904):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-20 12:07:32.203: ERROR/AndroidRuntime(8904):     at dalvik.system.NativeStart.main(Native Method)
02-20 12:07:32.226: WARN/ActivityManager(1308):   Force finishing activity com.commonsware.android.constants/.ConstantsBrowser

the null
is in
line latTxt.setText(String.valueOf(loc.getLatitude()));

how to fix that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T05:28:26+00:00Added an answer on June 19, 2026 at 5:28 am

    latTxt is null. Make sure you have a <TextView> with the id @+id/latitudeTxt in your layout XML file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is example which I have try <?php include 'spider/classes/simple_html_dom.php'; $html = new simple_html_dom();
So, here is the code that I have: try { PlayerSave save = new
i have try{ ..code.. }catch(err){ err.### what methods do i have access to here
i have try to develop one java app.here am getting information from mysql database.
Does anyone know what is it going on here? I have try to pass
i have try to develop one android app.here i have to develop forget password
I have try this code on DatabaseHelper.java Line Number 34 public DatabaseHelper(Context context) throws
i have try refox and see how eazy my EXE to be disassembled. the
I have try to set icon for my App in the xCode. In the
I have try { using (var eventWaitHandle = EventWaitHandle.OpenExisting(name)) { eventWaitHandle.Set(); } Environment.Exit(0); }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.