title: NullPointerException while using TinyDB
body: <p>I'm new to android (and not a veteran at all in java) developpment.</p>
  <p>Trying to do a weather app, I'm trying to use TinyDB as my storage for saved cities.
  A button on another activity let me add cities to a list (which I want to save).</p>
  <p>In my MainActivity's onCreate, I'm setting up my TinyDB. Then add a city stored in extra to my TinyDB if the MainActivity is launched from the addCityActivity. Finally, getting all the cities from TinyDB to print it to screen in a ListView. (user will then be able to click on a city to get weather information for this one)</p>
  <p>But then a NullPointerException raises and it seems to come from TinyDB and I have no idea how to resolve it, I'm stuck on it for a day now (doing this on my free time).</p>
  <p>Do you guys have any idea please ?</p>
  <p>TinyDB is <a href="https://github.com/kcochibili/TinyDB--Android-Shared-Preferences-Turbo#readme" rel="nofollow noreferrer">here</a>.</p>
  <p>And here's my MainActivity :</p>
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      private Context context;
      private ListView cityListView;
      private CitylistAdapter citylistAdapter;
  
      private List&lt;City&gt; cities = new ArrayList&lt;&gt;();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          TinyDB tinydb = new TinyDB(context);
  
          if (getIntent().getExtras() != null) {
              String name = getIntent().getStringExtra(&quot;City&quot;);
              ArrayList&lt;String&gt; cityList = tinydb.getListString(&quot;Cities&quot;);
              cityList.add(getIntent().getStringExtra(&quot;City&quot;));
              tinydb.putListString(&quot;Cities&quot;, cityList);
          }
  
          ArrayList&lt;String&gt; cityList = tinydb.getListString(&quot;Cities&quot;);
          for (int i = 0; i &lt; cityList.size(); i++) {
              City city = new City();
              city.setName(cityList.get(i));
              cities.add(city);
          }
  
          this.cityListView = (ListView) findViewById(R.id.cityList);
  
          this.citylistAdapter = new CitylistAdapter(getApplicationContext(), cities);
          this.cityListView.setAdapter(citylistAdapter);
  
          FloatingActionButton addCity = (FloatingActionButton) findViewById(R.id.openAddCity);
  
          addCity.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  startAddCityActivity();
              }
          });
      }
  
      private void startAddCityActivity() {
          Intent intent = new Intent(this, AddCityActivity.class);
          startActivity(intent);
      }
  }
  </code></pre>
  <p>And here's the stack trace :</p>
  <pre><code>2021-09-23 13:59:38.565 5754-5754/com.example.weather E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.weather, PID: 5754
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.weather/com.example.weather.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
          at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
          at android.os.Handler.dispatchMessage(Handler.java:106)
          at android.os.Looper.loop(Looper.java:223)
          at android.app.ActivityThread.main(ActivityThread.java:7656)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
       Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
          at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:555)
          at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:545)
          at com.example.weather.TinyDB.&lt;init&gt;(TinyDB.java:39)
          at com.example.weather.MainActivity.onCreate(MainActivity.java:51)
          at android.app.Activity.performCreate(Activity.java:8000)
          at android.app.Activity.performCreate(Activity.java:7984)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
          at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
          at android.os.Handler.dispatchMessage(Handler.java:106) 
          at android.os.Looper.loop(Looper.java:223) 
          at android.app.ActivityThread.main(ActivityThread.java:7656) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
  2021-09-23 13:59:38.600 5754-5754/com.example.weather I/Process: Sending signal. PID: 5754 SIG: 9
  </code></pre>