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 7817321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:11:43+00:00 2026-06-02T06:11:43+00:00

What I have Gives Me these errors. 04-13 15:01:41.600: E/AndroidRuntime(8431): FATAL EXCEPTION: main 04-13

  • 0

What I have Gives Me these errors.

04-13 15:01:41.600: E/AndroidRuntime(8431): FATAL EXCEPTION: main
04-13 15:01:41.600: E/AndroidRuntime(8431): java.lang.RuntimeException: Unable to start activity ComponentInfo    {com.omnilabs.alexandernapoles.hl2sticl/com.example.example.example.MainClass}: java.lang.NullPointerException
04-13 15:01:41.600: E/AndroidRuntime(8431):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at android.os.Looper.loop(Looper.java:137)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at android.app.ActivityThread.main(ActivityThread.java:4424)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at java.lang.reflect.Method.invokeNative(Native Method)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at java.lang.reflect.Method.invoke(Method.java:511)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at dalvik.system.NativeStart.main(Native Method)
04-13 15:01:41.600: E/AndroidRuntime(8431): Caused by: java.lang.NullPointerException
04-13 15:01:41.600: E/AndroidRuntime(8431):     at android.content.ContextWrapper.getPackageName(ContextWrapper.java:127)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at android.preference.PreferenceManager.getDefaultSharedPreferencesName    (PreferenceManager.java:371)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at android.preference.PreferenceManager.getDefaultSharedPreferences    (PreferenceManager.java:366)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at com.example.example.example.ShakeEventListener.<init>(ShakeEventListener.java:24)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at com.example.example.example.MainClass.onCreate(StunBatton.java:38)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at android.app.Activity.performCreate(Activity.java:4465)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-13 15:01:41.600: E/AndroidRuntime(8431):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-13 15:01:41.600: E/AndroidRuntime(8431):     ... 11 more

And here is part of my shakevent listener class that involves preferences

public class ShakeEventListener extends Application implements SensorEventListener {
public void onCreate(Bundle savedInstanceState) {

    super.onCreate();


}
SharedPreferences preferences =
         PreferenceManager.getDefaultSharedPreferences(this);


private String editTextPref = getString(R.string.preference_key);
int nVar = preferences.getInt(editTextPref, MODE_PRIVATE);
int MIN_FORCE = nVar;
/**
* Minimum times in a shake gesture that the direction of movement needs to
* change.
*/
private static final int MIN_DIRECTION_CHANGE = 15;

/** Maximum pause between movements. */
private static final int MAX_PAUSE_BETHWEEN_DIRECTION_CHANGE = 50000;

etc etc

preferences.java

package com.example.example.example;

import android.os.Bundle;
import android.preference.PreferenceActivity;

public class Preferences extends PreferenceActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                addPreferencesFromResource(R.layout.preferences);


        }
}

Preferences.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
        <PreferenceCategory
                android:title="First Category">
        <EditTextPreference
                android:name="Stun Swing Sensitivity"
                android:summary="This allows you to custom fit your sensitivity."
                android:defaultValue="10"
               android:numeric="integer"
                android:maxLength="200"
                android:title="Sensitivity Level"
                android:key="@string/preference_key" />
        </PreferenceCategory>

</PreferenceScreen>

Inside of strings.xml i put
editTextPref

So Basically I just want to know how I can use a variable in a class file that an activity calls for shaking then it uses onShake(); to call from the shake activity, But I want to save MIN_FORCE as a variable nVar and nVar be the setting in the preference files thats an integer.

Please Help!!!!!!!!!

EDIT:
I know it has to do with this code

      SharedPreferences preferences =
             PreferenceManager.getDefaultSharedPreferences(this);
 String editTextPref = getString(R.string.preference_key);
nVar = preferences.getInt(editTextPref, 10);
  • 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-02T06:11:44+00:00Added an answer on June 2, 2026 at 6:11 am

    You have to move the call to getDefaultSharedPreferences inside onCreate (or a later callback). It does not work outside because at object construction time your Activity isn’t fully set up.

    public class ShakeEventListener extends Application implements SensorEventListener {
    
    int nVar = 0;
    public void onCreate(Bundle savedInstanceState) {
    
        super.onCreate();
        SharedPreferences preferences =
             PreferenceManager.getDefaultSharedPreferences(this);
    
    
        private String editTextPref = getString(R.string.preference_key);
        nVar = preferences.getInt(editTextPref, MODE_PRIVATE);
        int MIN_FORCE = nVar;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cshtml page that gives these errors: Uncaught ReferenceError: $ is not
No matter which way I mix it, it gives me errors. I have a
EDIT omg I clearly should take a break... logcat gives these errors and as
It gives these errors The type Email must implement the inherited abstract method Comparable.compareTo(Object)
I have implemented a very basic Stack in Java which is giving strange errors
I have a process which gives me continuously output in Screen. I want to
I have a gridiview which gives me a output of 20 members in a
I have the jquery: $(.item) which gives me all elements of class item. I
I'm upgrading to Rails 3.2, and running rake db:migrate gives me several errors of
I have a list of lists, eg [[1;2;3];[2];[3;4;5;6]; [7;8;9;10] I want to place these

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.