android-context

Getting file from assets using getAssets() consistently fails

冷暖自知 提交于 2019-12-13 08:38:55
问题 In the code I have listed below, the method getPieceTextFile() should return the InputStream to read data from the specified file. However, the method always falls back on the catch and so returns null, leading to a NPE. I have listed the LogCat output and the code for the class below. Any identification of the potential source of the problem would be appreciated. LogCat: 01-03 12:17:51.331: I/dalvikvm(589): threadid=3: reacting to signal 3 01-03 12:17:51.590: I/dalvikvm(589): Wrote stack

Using the AltBeacon library without extending Application

强颜欢笑 提交于 2019-12-13 05:25:32
问题 I have an Android Application that among other things monitor beacons using the AltBeacon library. My problem is that, from my understanding, to have a class monitoring beacons you must make this class extend Application. But I already have a class extending Application. Now I cant make my other class not extend Application and I cant make my " beaconClass " extend this class. My only option is to find a way to use the AltBeacon library without extending Application. So I would like to know

NullPointerException when starting ListActivity

馋奶兔 提交于 2019-12-13 05:06:41
问题 I'm working for hours on an error I get, when I want to start a ListActivity. Short workaround about what I want to do: I have a main application with a normal menu, from which I want to start a setting list where the user can add specific settings. I'm trying to start the ListView like this: startActivity(new Intent(this, FileManagerSettings.class)); Then in the on Create method I got the error: userSettings = deserializeObject(); if(userSettings.isEmpty()) { userSettings.add(new SettingItem

Declare view elements in another class (context not clear)

偶尔善良 提交于 2019-12-13 04:33:51
问题 I am creating a dynamic UI programatically and in main class I am creating UI element so that I can later add it to TableLayout view. Normally I declare it like this: TextView tw_1_2 = new TextView(this); where this is the context. Since I never get to understand context clearly can someone tell me how can I declare this TextView in another class (as public static for example) and what should I put in context if I want to declare this view in some other class? 回答1: Basically you have to send

Android context using “this” on class that is not an activity

大城市里の小女人 提交于 2019-12-13 03:08:20
问题 I created the following class to populate a listView with two different kinds of views. One of the two kinds contain is a spinner, which I'm trying to populate with Arraylists (one for each spinner) contained in the bundle. The problem I'm dealing with is the ArrayAdapter constructor, which clearly has a problem with the context I'm using ("this"). Any ideas? public class InsertAdapter extends BaseAdapter { private static final int OWN_KEY = 0; private static final int FOREIGN_KEY = 1;

android toolbar color is turning to blue when come from fragment

二次信任 提交于 2019-12-13 02:51:09
问题 I have an app that works without problems.In this app, I display the products from the server.When you click on one of the products, we enter the details activity to show details.Everything works fine.But when I go to this activity from one of the other pages of the program, which is a fragment(an activity with tab and view pager and fragments) .The color of the toolbar and the imageview that is white is changed to blue help me please it is my fragment code: public class CatFragment extends

Sharedpreferences in Android returns null when called from another activity

时间秒杀一切 提交于 2019-12-13 01:43:14
问题 I made two activities, one for the widget and one for the settings activity. There are two variables "strSavedMem1" & "strSavedMem1" initialised in the settings activity... and are made via sharedPreference method. But when I try to use the variable in widget activity, the variable return a "null" value. The widget Activity: package com.eightbitcloud.example.widget; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Calendar; import

How should I go about getting Context in this case?

╄→гoц情女王★ 提交于 2019-12-12 18:33:43
问题 I have to design a Sensor Manager class on top of sensors like accelerometer , compass etc. This project will be a class library project that will be referenced and used in other android projects that need data from sensor devices. Problem is that in order to play with devices like accelerometer and compass in my Sensor Manager class I need Context . I can't figure out how can I access the current context in this scenario. Should I ask the callers/users of my Sensor Manager to pass the

Initialize boolean value “no such instance field”

血红的双手。 提交于 2019-12-12 18:15:40
问题 I get an error in debugging and I can't set this boolean value. I attached a screenshot of the error. I call DeviceUpdateManager in my mainActivity like this: public class MainActivity extends AppCompatActivity implements DeviceUpdateManager.OnDataCOM { DeviceUpdateManager deviceUpdateManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.deviceUpdateManager = new DeviceUpdateManager(this.serverCOM,this.getApplicationContext(),this); }

How to use context inside listener?

你说的曾经没有我的故事 提交于 2019-12-12 17:06:00
问题 I have code like this: else if (v == mSettings) { if (disappearView.getVisibility() == View.VISIBLE) { AlphaAnimation fadeOutAnimation = new AlphaAnimation(1, 0); // start alpha, end alpha fadeOutAnimation.setDuration(1000); // time for animation in milliseconds fadeOutAnimation.setFillAfter(true); // make the transformation persist Animation out = AnimationUtils.makeOutAnimation(this, true); disappearView.startAnimation(out); disappearView.setVisibility(View.INVISIBLE); out