Couldn't use getRefrence() with firebase in android - android

iv'e been stuck for hours trying to figure out what's the problem...
every time I try to access the reference the up crushes.
tried to open like 5 new projects and firebases....
MainActivity( only realated stuff):
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private Button ba;
FirebaseDatabase database;
DatabaseReference myRef;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ba=findViewById(R.id.ba);
ba.setOnClickListener(this);
}
#Override
public void onClick(View view) {
if(view==ba)
{
database = FirebaseDatabase.getInstance();
myRef=database.getReference("Foods"); //this is where it crushes
// myRef.setValue("ba");
}
}
}
The Run Log:
E/RunLoop: Uncaught exception in Firebase Database runloop (3.0.0). Please report to firebase-database-client#google.com
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/FirebaseApp$IdTokenListener;
at com.google.firebase.database.android.AndroidPlatform.newAuthTokenProvider(com.google.firebase:firebase-database##16.0.4:112)
at com.google.firebase.database.core.Context.ensureAuthTokenProvider(com.google.firebase:firebase-database##16.0.4:246)
at com.google.firebase.database.core.Context.initServices(com.google.firebase:firebase-database##16.0.4:98)
at com.google.firebase.database.core.Context.freeze(com.google.firebase:firebase-database##16.0.4:77)
at com.google.firebase.database.core.RepoManager.createLocalRepo(com.google.firebase:firebase-database##16.0.4:92)
at com.google.firebase.database.core.RepoManager.createRepo(com.google.firebase:firebase-database##16.0.4:42)
at com.google.firebase.database.FirebaseDatabase.ensureRepo(com.google.firebase:firebase-database##16.0.4:357)
at com.google.firebase.database.FirebaseDatabase.getReference(com.google.firebase:firebase-database##16.0.4:201)
at com.example.caloriccalcyair1.MainActivity.onClick(MainActivity.java:43)
at android.view.View.performClick(View.java:7869)
at android.widget.TextView.performClick(TextView.java:14958)
at android.view.View.performClickInternal(View.java:7838)
at android.view.View.access$3600(View.java:886)
at android.view.View$PerformClick.run(View.java:29362)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8016)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.FirebaseApp$IdTokenListener" on path: DexPathList[[zip file "/data/app/com.example.caloriccalcyair1-mv4wi0pKnsqKEHcy89c_hA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.caloriccalcyair1-mv4wi0pKnsqKEHcy89c_hA==/lib/arm64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.google.firebase.database.android.AndroidPlatform.newAuthTokenProvider(com.google.firebase:firebase-database##16.0.4:112) 
at com.google.firebase.database.core.Context.ensureAuthTokenProvider(com.google.firebase:firebase-database##16.0.4:246) 
at com.google.firebase.database.core.Context.initServices(com.google.firebase:firebase-database##16.0.4:98) 
at com.google.firebase.database.core.Context.freeze(com.google.firebase:firebase-database##16.0.4:77) 
at com.google.firebase.database.core.RepoManager.createLocalRepo(com.google.firebase:firebase-database##16.0.4:92) 
at com.google.firebase.database.core.RepoManager.createRepo(com.google.firebase:firebase-database##16.0.4:42) 
at com.google.firebase.database.FirebaseDatabase.ensureRepo(com.google.firebase:firebase-database##16.0.4:357) 
at com.google.firebase.database.FirebaseDatabase.getReference(com.google.firebase:firebase-database##16.0.4:201) 
at com.example.caloriccalcyair1.MainActivity.onClick(MainActivity.java:43) 
at android.view.View.performClick(View.java:7869) 
at android.widget.TextView.performClick(TextView.java:14958) 
at android.view.View.performClickInternal(View.java:7838) 
at android.view.View.access$3600(View.java:886) 
at android.view.View$PerformClick.run(View.java:29362) 
at android.os.Handler.handleCallback(Handler.java:883) 
at android.os.Handler.dispatchMessage(Handler.java:100) 
at android.os.Looper.loop(Looper.java:237) 
at android.app.ActivityThread.main(ActivityThread.java:8016) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076) 
i followed the firebase installation step by step and verifyed the project.
also added the firebase to the porject with the Tools option, so everything should be ok
image of the firebase database

Instead of using your code.
Try using this:
database = FirebaseDatabase.getInstance().getReference().child("Foods");
And also try wrapping your on click listener like this inside onCreate
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
...
}
});

Related

Android Checkbox error "on a null object reference" [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
I tried to make a checkbox that when it is checked it will strikethrough text field elements in the listview. I'm pretty sure that I did everything correctly including set up the ID for the checkbox in XML and declared it on the class that I wanna use but I still get the Null object error.
I have looked through all the question and answer all over this topic, I also tried them all but I still get an error. Could someone please help me identify where an error might be.
Thank you so much in advance for any help =)
Class file
package com.puyakul.prin.psychic_shopping;
import...
public class MainListView extends AppCompatActivity {
//================DATABASE=====================//
private ShoppingListDatabase databaseConnection;
private SQLiteDatabase db;
public ListView ListView_mainListView;
public ArrayList<ShoppingList> lists;
public AppCompatCheckBox checkBox_doneCheck;
public TextView textView_listname;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//================DATABASE Connection================//
databaseConnection = new ShoppingListDatabase(this);
db = databaseConnection.open();
//important!!!
setContentView(R.layout.activity_main_list_view);
getLists();
}
public void getLists(){
....
******Original here, but I delete by acident******
checkBox_doneCheck = findViewById(R.id.checkBox_doneCheck);
checkBox_doneCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if (checkBox_doneCheck.isChecked()) {
textView_listname.setPaintFlags(textView_listname.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
else{
textView_listname.setPaintFlags(textView_listname.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
}
}
});
}
XML file
<android.support.v7.widget.AppCompatCheckBox
android:id="#+id/checkBox_doneCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:checked="false"/>
Error log
Process: com.puyakul.prin.psychic_shopping, PID: 19958
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.puyakul.prin.psychic_shopping/com.puyakul.prin.psychic_shopping.MainListView}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.AppCompatCheckBox.setOnCheckedChangeListener(android.widget.CompoundButton$OnCheckedChangeListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.AppCompatCheckBox.setOnCheckedChangeListener(android.widget.CompoundButton$OnCheckedChangeListener)' on a null object reference
at com.puyakul.prin.psychic_shopping.MainListView.getLists(MainListView.java:107)
at com.puyakul.prin.psychic_shopping.MainListView.onCreate(MainListView.java:67)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
You never initialize checkBox_doneCheck, try this instead in onCreate:
setContentView(R.layout.activity_main_list_view);
checkBox_doneCheck = (AppCompatCheckBox) findViewById(R.id.checkBox_doneCheck);
getLists();
You may also want to do something similar with those variables:
ListView_mainListView
textView_listnameist item
You are missing the association between the xml and java code.
Add this line:
checkBox_doneCheck = findViewById(R.id.checkBox_doneCheck)
Thats why you are having the NullPointerException.

Android application crashes when run in my phone from the android studio [duplicate]

This question already has answers here:
java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)
(16 answers)
Closed 4 years ago.
I am a beginner in programming and trying to work on an sample project in android studio but my application crashes when i run it in my phone.
Please help me. What can be done?
I am getting this error when i checked in logcat.
01-06 13:18:20.778 13471-13471/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hof_university.chethan.chatmessenger, PID: 13471
java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface; in class Landroid/support/v4/content/res/ResourcesCompat; or its super classes (declaration of 'android.support.v4.content.res.ResourcesCompat' appears in /data/app/com.hof_university.chethan.chatmessenger-2/split_lib_dependencies_apk.apk)
at android.support.v7.widget.TintTypedArray.getFont(TintTypedArray.java:119)
at android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:208)
at android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:110)
at android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:81)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:71)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:67)
at android.support.v7.widget.Toolbar.setTitle(Toolbar.java:753)
at android.support.v7.widget.ToolbarWidgetWrapper.setTitleInt(ToolbarWidgetWrapper.java:261)
at android.support.v7.widget.ToolbarWidgetWrapper.setWindowTitle(ToolbarWidgetWrapper.java:243)
at android.support.v7.widget.ActionBarOverlayLayout.setWindowTitle(ActionBarOverlayLayout.java:621)
at android.support.v7.app.AppCompatDelegateImplV9.onTitleChanged(AppCompatDelegateImplV9.java:631)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.hof_university.chethan.chatmessenger.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:6177)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2541)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
at android.app.ActivityThread.access$900(ActivityThread.java:188)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1530)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:210)
at android.app.ActivityThread.main(ActivityThread.java:5839)
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:1113)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:879)
MainActivity
public class MainActivity extends AppCompatActivity {
private EditText editMessage;
private DatabaseReference mDatabase;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editMessage = (EditText) findViewById(R.id.editMessageE);
mDatabase = FirebaseDatabase.getInstance().getReference().child("Messages");
}
public void sendButtonClicked(View view){
final String messageValue = editMessage.getText().toString().trim();
if (!TextUtils.isEmpty(messageValue)){
final DatabaseReference newPost = mDatabase.push();
newPost.child("content").setValue(messageValue);
}
}
}
I checked the official document, getFont this method is added after the api 27, and need to add com.android.support:support-compat:27.0.0 in build.gradle file. It belongs to ResourcesCompat
ResourcesCompat
android doc getFont
Try this
implementation 'com.android.support:recyclerview-v7:27.0.2'
implementation 'com.android.support:appcompat-v7:27.0.2'
and this
buildToolsVersion 27.0.2
compileSdkVersion 27.0.2

Twitter button click crashing app ? Unable to extract the trust manager on okhttp3.internal.Platform$Android

issues is with Twitter button, this is working fine with Android 6 Moto G, while on android 5.0.1 Samsung Note 3 it crashes, on Simulator it works fine too,
However my code for Click is,
TwitterLoginButton twitterLoginButton = (TwitterLoginButton) findViewById(R.id.button_twitter);
twitterLoginButton.setCallback(new Callback<TwitterSession>() {
#Override
public void success(Result<TwitterSession> result) {
Log.d(TAG, "twitterLogin:success" + result);
handleTwitterSession(TwitterAuthProvider.getCredential(
result.data.getAuthToken().token,
result.data.getAuthToken().secret), false);
}
#Override
public void failure(TwitterException exception) {
Log.w(TAG, "twitterLogin:failure", exception);
}
});
twitterLoginButton.setOnClickListener(this);
Issues it is showing is,
java.lang.RuntimeException:Unable to start activity ComponentInfo{com.my.project/com.twitter.sdk.android.core.identity.OAuthActivity}: java.lang.IllegalStateException: Unable to extract the trust manager on okhttp3.internal.Platform$Android#2e0793c7, sslSocketFactory is class crittercism.android.q
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
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:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: java.lang.IllegalStateException: Unable to extract the trust manager on okhttp3.internal.Platform$Android#2e0793c7, sslSocketFactory is class crittercism.android.q
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:187)
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:60)
at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:718)
at com.twitter.sdk.android.core.internal.oauth.OAuthService.<init>(OAuthService.java:56)
at com.twitter.sdk.android.core.internal.oauth.OAuth1aService.<init>(OAuth1aService.java:69)
at com.twitter.sdk.android.core.identity.OAuthActivity.onCreate(OAuthActivity.java:69)
at android.app.Activity.performCreate(Activity.java:6283)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758) 
at android.app.ActivityThread.access$900(ActivityThread.java:177) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:145) 
at android.app.ActivityThread.main(ActivityThread.java:5942) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
i searched a lot on google but unable to find any helpful, solution.
This is a problem with Crittercism. If updating that doesn't help you'll need to report the bug to them.

Android: Crash when setting up media route button

I'm having pretty much the same problem as Android: Cast SDK v3 Crashing in Release build only.
The key difference is that my project does it while i'm just debugging and does it on this line
CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), mMediaRouteButton);
I have tried making all my variables public but that doesn't do anything. The full code is
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMediaRouteButton = (MediaRouteButton) findViewById(R.id.media_route_button);
CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), mMediaRouteButton);
mCastContext = CastContext.getSharedInstance(this);
mSelector = new MediaRouteSelector.Builder()
// These are the framework-supported intents
.addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
.addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
.build();
mMediaRouter = MediaRouter.getInstance(this);
}
Also I find it worth mentioning that this code worked and I can not for the life of me figure out what caused it to stop working. As far as I can tell it stopped working when I invalidated the cache in Android Studio.
This is the error I'm getting
java.lang.RuntimeException: Unable to start activity ComponentInfo{mypackage.package/mypackage.package.MainActivity}: java.lang.IllegalStateException: Failed to initialize CastContext.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.IllegalStateException: Failed to initialize CastContext.
at com.google.android.gms.cast.framework.CastContext.zzbb(Unknown Source)
at com.google.android.gms.cast.framework.CastContext.getSharedInstance(Unknown Source)
at com.google.android.gms.cast.framework.CastButtonFactory.setUpMediaRouteButton(Unknown Source)
at mypackage.package.MainActivity.onCreate(MainActivity.java:51)
at android.app.Activity.performCreate(Activity.java:6664)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
Caused by: java.lang.IllegalAccessException: java.lang.Class<mypackage.package.CastOptionsProvider> is not accessible from java.lang.Class<com.google.android.gms.cast.framework.CastContext>
at java.lang.Class.newInstance(Native Method)
at com.google.android.gms.cast.framework.CastContext.zzbb(Unknown Source) 
at com.google.android.gms.cast.framework.CastContext.getSharedInstance(Unknown Source) 
at com.google.android.gms.cast.framework.CastButtonFactory.setUpMediaRouteButton(Unknown Source) 
at mypackage.package.MainActivity.onCreate(MainActivity.java:51) 
at android.app.Activity.performCreate(Activity.java:6664) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
There might be an issue on how you initialize media CastContext, to properly initialize CastContext, the application must have the implements OptionsProvider interface:
package com.example.app;
public class CastOptionsProvider implements OptionsProvider {
#Override
public CastOptions getCastOptions(Context appContext) {
...
}
}
and specify its fully qualified class name in the AndroidManifest.xml with the key OPTIONS_PROVIDER_CLASS_NAME_KEY:
...
<meta-data
android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
android:value="com.example.app.CastOptionsProvider" />
...
Note: All public methods must be called from the main thread.
I did some research and found this related SO ticket which discuss how to initialize CastContext: How to initialize CastContext outside of onCreate method
This was fixed by making the CastOptionsProvider public. I don't know why this problem occurred to begin with, because it was working fine when it wasn't public until it didn't. I didn't touch the CastOptionsProvider on the build where it started failing.
My CastOptionsProvider now looks like this
public class CastOptionsProvider implements OptionsProvider {
#Override
public CastOptions getCastOptions(Context appContext) {
CastOptions castOptions = new CastOptions.Builder()
.setReceiverApplicationId(appContext.getString(R.string.app_id))
.build();
return castOptions;
}
#Override
public List<SessionProvider> getAdditionalSessionProviders(Context context) {
return null;
}
}
If this is happening only in release buildtype then it is related to proguard. Please add the CastOptionsProvider class to the proguard file and recheck
-keep class abc.xyz.videocast.CastOptionsProvider { *; }
For more safety these classes can also be added
-keep class android.support.** { *; }
-keep class com.google.** { *; }

class not found and null object reference exception out of nowhere

I have now completed all the scripting and designing with no compile time error but out of no where this run time error comes in and my app flashes away and do not get launched.
I have got all the files that it requires and everything done,
Please suggest now,
This is my MainActivity.java code thats probably throwing these exceptions
package com.example.dell.demologin;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.HashMap;
import activity.LoginActivity;
import helper.SQLiteHandler;
import helper.SessionManager;
public class MainActivity extends Activity {
private TextView txtName;
private TextView txtEmail;
private Button btnLogout;
private SQLiteHandler db;
private SessionManager session;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
txtName = (TextView) findViewById(R.id.name);
txtEmail = (TextView) findViewById(R.id.email);
btnLogout = (Button) findViewById(R.id.btnLogout);
// SqLite database handler
db = new SQLiteHandler(getApplicationContext());
// session manager
session = new SessionManager(getApplicationContext());
if (!session.isLoggedIn()) {
logoutUser();
}
// Fetching user details from sqlite
HashMap<String, String> user = db.getUserDetails();
String name = user.get("name");
String email = user.get("email");
// Displaying the user details on the screen
txtName.setText(name);
txtEmail.setText(email);
// Logout button click event
btnLogout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
logoutUser();
}
});
}
/**
* Logging out the user. Will set isLoggedIn flag to false in shared
* preferences Clears the user data from sqlite users table
* */
private void logoutUser() {
session.setLogin(false);
db.deleteUsers();
// Launching the login activity
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
}
This is my logcat,
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dell.demologin, PID: 15578
java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.IllegalStateException: java.lang.ClassNotFoundException: com.example.dell.demologin.AppController
at android.app.LoadedApk.makeApplication(LoadedApk.java:601)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4757)
at android.app.ActivityThread.access$1600(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:152)
at android.app.ActivityThread.main(ActivityThread.java:5507)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: java.lang.ClassNotFoundException: com.example.dell.demologin.AppController
at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:220)
at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239)
at android.app.Application.attach(Application.java:187)
at android.app.Instrumentation.newApplication(Instrumentation.java:1001)
at android.app.Instrumentation.newApplication(Instrumentation.java:985)
at android.app.LoadedApk.makeApplication(LoadedApk.java:586)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4757) 
at android.app.ActivityThread.access$1600(ActivityThread.java:159) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:152) 
at android.app.ActivityThread.main(ActivityThread.java:5507) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.ClassNotFoundException: com.example.dell.demologin.AppController
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:324)
at java.lang.Class.forName(Class.java:285)
at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:209)
at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239) 
at android.app.Application.attach(Application.java:187) 
at android.app.Instrumentation.newApplication(Instrumentation.java:1001) 
at android.app.Instrumentation.newApplication(Instrumentation.java:985) 
at android.app.LoadedApk.makeApplication(LoadedApk.java:586) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4757) 
at android.app.ActivityThread.access$1600(ActivityThread.java:159) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:152) 
at android.app.ActivityThread.main(ActivityThread.java:5507) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.dell.demologin.AppController" on path: DexPathList[[zip file "/data/app/com.example.dell.demologin-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.dell.demologin-2/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:324) 
at java.lang.Class.forName(Class.java:285) 
at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:209) 
at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239) 
at android.app.Application.attach(Application.java:187) 
at android.app.Instrumentation.newApplication(Instrumentation.java:1001) 
at android.app.Instrumentation.newApplication(Instrumentation.java:985) 
at android.app.LoadedApk.makeApplication(LoadedApk.java:586) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4757) 
at android.app.ActivityThread.access$1600(ActivityThread.java:159) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:152) 
at android.app.ActivityThread.main(ActivityThread.java:5507) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Suppressed: java.lang.ClassNotFoundException: Didn't find class "com.example.dell.demologin.AppController" on path: DexPathList[[dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-support-annotations-23.4.0_2f85958e3577c0887206665b958d529f2917b10d-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-mysql-connector-java_910883ba1d0637ad761451367a22e76261a44141-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-jtds_dd6bef0a517729fc55f6897f784dfc3379233a03-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-internal_impl-23.4.0_acbefc0422230ccc1164ab
E/AndroidRuntime: Error reporting crash
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.app.Application.getApplicationContext()' on a null object reference
at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:96)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
I/Process: Sending signal. PID: 15578 SIG: 9
Application terminated.
Known bug in the Google Play store upgrade process, https://code.google.com/p/android/issues/detail?id=56296

Categories

Resources