ParseTwitterUtils initialize throws NullPointerException - android

I am getting a NullPointerException from calling
ParseTwitterUtils.initialize(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
Here is the stack trace
java.lang.RuntimeException: Unable to create application com.myapp.app.android.Application: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getParseDir()' on a null object reference
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5015)
at android.app.ActivityThread.access$1600(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1482)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5837)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getParseDir()' on a null object reference
at com.parse.Parse.getParseDir(Parse.java:313)
at com.parse.ParseCorePlugins.getCurrentUserController(ParseCorePlugins.java:124)
at com.parse.ParseUser.getCurrentUserController(ParseUser.java:56)
at com.parse.ParseUser.getCurrentUser(ParseUser.java:892)
at com.parse.ParseUser.getCurrentUser(ParseUser.java:879)
at com.parse.ParseUser.registerAuthenticationProvider(ParseUser.java:1125)
at com.parse.ParseTwitterUtils.getAuthenticationProvider(ParseTwitterUtils.java:20)
at com.parse.ParseTwitterUtils.initialize(ParseTwitterUtils.java:50)
at com.myapp.app.android.Application.onCreate(Application.java:42)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1020)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5012)
            at android.app.ActivityThread.access$1600(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1482)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5837)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
My app used to work before I added the line ParseTwitterUtils.initialize(...). Here is the onCreate method of my Application class
public void onCreate(){
super.onCreate();
registerDatabaseTables();
ParseTwitterUtils.initialize(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
Parse.enableLocalDatastore(this);
Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
}

Unfortunately the instructions on parse.com do not say this, but you have to initialize Parse before you initialize Twitter. This is not obvious since you are required to do so much before you initialize parse. So anyway change your code to this:
public void onCreate(){
super.onCreate();
registerDatabaseTables();
Parse.enableLocalDatastore(this);
Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
ParseTwitterUtils.initialize(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
}

Related

android.content.res.Resources android.content.Context.getResources() error when using github repository

I am using https://github.com/BlacKCaT27/CurrencyEditText to enter currency into my application and I am using this code:
CurrencyEditText cet = new CurrencyEditText(this, null);
Here is the logcat:
Process: com.dharquissandas.budget, PID: 17620
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.dharquissandas.budget/com.dharquissandas.budget.add_expense}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2819)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
at android.content.ContextWrapper.getResources(ContextWrapper.java:86)
at android.view.ContextThemeWrapper.getResourcesInternal(ContextThemeWrapper.java:127)
at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:121)
at android.support.v7.app.AppCompatActivity.getResources(AppCompatActivity.java:542)
at android.view.View.<init>(View.java:4306)
at android.view.View.<init>(View.java:4454)
at android.widget.TextView.<init>(TextView.java:995)
at android.widget.EditText.<init>(EditText.java:79)
at android.widget.EditText.<init>(EditText.java:75)
at android.widget.EditText.<init>(EditText.java:71)
at com.blackcat.currencyedittext.CurrencyEditText.<init>(CurrencyEditText.java:33)
at com.dharquissandas.budget.add_expense.<init>(add_expense.java:29)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1086)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2809)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
What am I doing wrong I don't know, I am fairly new to android programming can someone help me out. What am I supposed to put in the attribute part of the code?
Here is my code: https://pastebin.com/57mTUMWX
You should not be creating view elements in your Code.
Add the view for CurrencyText to your XML.
Then you make sure it has an #+id/myName and find it by doing
CurrencyText myText = findViewById(R.id.myName);

android - getActionBar() return null

i have a problem with getActionBar(), this problem happens when i'm trying to change view of action bar , i'm getting this error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{h.ui01/h.ui01.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setNavigationMode(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3119)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
at android.app.ActivityThread.access$1000(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6837)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setNavigationMode(int)' on a null object reference
at h.ui01.MainActivity.onCreate(MainActivity.java:28)
at android.app.Activity.performCreate(Activity.java:6500)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
            at android.app.ActivityThread.access$1000(ActivityThread.java:198)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:6837)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
My code is here :
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.action_bar, null);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
}
}
even when i try to hide action bar or change color of the action bar , i saw similar error.

How to get image name from imageview

I have an imageview which has an image loaded in it. This way
// create bitmap from resource
Bitmap bm = BitmapFactory.decodeResource(getResources(),
R.drawable.profile_blank_xlarge);
// set circle bitmap
ImageView mImage = (ImageView) layout.findViewById(R.id.image);
mImage.setImageBitmap(getCircleBitmap(bm));
I want to be able to find out the name of the image in the ImageView once the application is run.
I tried doing mImage.getTag() to get the name of the image in the ImageView but it crashes my app.
What is the correct way to get the name of the image in a ImageView
Crash Details
--------- beginning of crash
07-02 13:11:37.259 2096-2096/com.example.kmi_dev.fbloginsample E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.kmi_dev.fbloginsample, PID: 2096
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.kmi_dev.fbloginsample/com.example.kmi_dev.fbloginsample.MyActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at com.example.kmi_dev.fbloginsample.MyAccount.onCreateView(MyAccount.java:115)
at android.app.Fragment.performCreateView(Fragment.java:2053)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.app.BackStackRecord.run(BackStackRecord.java:834)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
at android.app.Activity.performStart(Activity.java:6005)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

AudioManager setStreamMute() Null Pointer Exception

I am getting Null Pointer Exception on line 219: amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);. It was not happening before, today i saw it first time, i am using Android 5.0. Code mutes notification sound when activity starts and unmutes when it is destroyed.
Code:
private AudioManager amanager;
#Override
protected void onCreate(Bundle savedInstanceState) {
amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
}
#Override
protected void onResume() {
super.onResume();
if(amanager!=null) {
amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
}
}
#Override
protected void onPause() {
if(amanager!=null) {
amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false);
}
super.onPause();
}
Error:
java.lang.RuntimeException: Unable to resume activity {com.jemshit.itu/com.jemshit.nfcAttendance.ClassActivity}: java.lang.NullPointerException: Null pointer exception during instruction 'invoke-static {v0}, android.os.IBinder android.media.AudioService$VolumeStreamState$VolumeDeathHandler.access$5300(android.media.AudioService$VolumeStreamState$VolumeDeathHandler) // method#11492'
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3346)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3377)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2728)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NullPointerException: Null pointer exception during instruction 'invoke-static {v0}, android.os.IBinder android.media.AudioService$VolumeStreamState$VolumeDeathHandler.access$5300(android.media.AudioService$VolumeStreamState$VolumeDeathHandler) // method#11492'
at android.os.Parcel.readException(Parcel.java:1546)
at android.os.Parcel.readException(Parcel.java:1493)
at android.media.IAudioService$Stub$Proxy.setStreamMute(IAudioService.java:992)
at android.media.AudioManager.setStreamMute(AudioManager.java:1466)
at com.jemshit.nfcAttendance.ClassActivity.onResume(ClassActivity.java:219)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1255)
at android.app.Activity.performResume(Activity.java:6338)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3335)
            at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3377)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2728)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5832)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
It's an Android bug it's not your code. Put a try/catch block in your code to avoid the crash.

Android Application Subclass Across Activities

I'm running into a NullPointerException, and I can't seem to figure out why. I wouldn't say I'm that experienced in android, so it seems easy for me to get lost when debugging these... :(
I've got an Application subclass defined as follows:
public class UserData extends Application {
private String email, firstName, lastName;
public String getEmail() {
return email;
}
public void setEmail(String str) {
email = str;
}
}
In one activity (loginpage), I set the email string:
UserData user = (UserData)getApplication();
user.setEmail(results);
When I log getEmail(), I see the results in this activity just fine.
In another activity (dashboard), I get the email string as follows:
UserData user = (UserData)getApplication();
Log.d("Email: ", user.getEmail());
This time, user.getEmail() returns a nullpointer. Can someone point out why this is occurring? I've got the subclass defined in my Manifest like this:
<application
android:name=".UserData"></application>
Error Log:
-12 18:10:51.261 19471-19471/habitatfinal.habitatfinal E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: habitatfinal.habitatfinal, PID: 19471
java.lang.RuntimeException: Unable to start activity ComponentInfo{habitatfinal.habitatfinal/habitatfinal.habitatfinal.dashboard}: java.lang.NullPointerException: println needs a message
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2411)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2474)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.d(Log.java:139)
at habitatfinal.habitatfinal.dashboard.onCreate(dashboard.java:29)
at android.app.Activity.performCreate(Activity.java:5958)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2474)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:155)
            at android.app.ActivityThread.main(ActivityThread.java:5696)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
I found out what was going on. The problem is onPostExecute doesn't necessarily run after the onCreate() method finishes running. Because they are two different threads, the subclass may not be initialized before the program passes the intent into the next activity.
Therefore, the variables in the object weren't set before it hit the new Activity.

Categories

Resources