Creating a NotificationChannel throws an IllegalArgumentException - android

The app works on previous versions of Android, but not on Oreo. It's a WebView with Notifications. I've been researching this error and haven't found anything similar.
The stack trace:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: net.oneteamit.tk, PID: 3171
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.oneteamit.tk/net.oneteamit.tk.MainActivity}:
java.lang.IllegalArgumentException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalArgumentException
at android.os.Parcel.readException(Parcel.java:1946)
at android.os.Parcel.readException(Parcel.java:1888)
at android.app.INotificationManager$Stub$Proxy.createNotificationChannels(INotificationManager.java:1418)
at android.app.NotificationManager.createNotificationChannels(NotificationManager.java:446)
at android.app.NotificationManager.createNotificationChannel(NotificationManager.java:434)
at net.oneteamit.tk.MainActivity.onCreate(MainActivity.java:47)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6541) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
MainActivity:
public class MainActivity extends AppCompatActivity {
private WebView mWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("My test URL");
mWebView.setWebViewClient(new WebViewClient());
mWebView.getSettings().setAppCacheEnabled(false);
mWebView.clearCache(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Create channel to show notifications.
String channelId = getString(R.string.default_notification_channel_id);
String channelName = getString(R.string.default_notification_channel_name);
NotificationManager notificationManager =
getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(
new NotificationChannel(channelId,
channelName,
NotificationManager.IMPORTANCE_LOW));
}
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.setInitialScale(1);
mWebView.getSettings().setBuiltInZoomControls(true);
}
}

This exception occurs when the channel name is invalid. I was able to reproduce the stack trace by running with an empty channel name:
<string name="default_notification_channel_name"></string>
Check the value you have defined for default_notification_channel_name and change it to a valid value.

<string name="app_name"></string> was the reason of this error. Empty string causes FATAL EXCEPTION.

AppCompactActivity is backward compatible but not forward compatible,are there any components that you are using that are not supported by Android 8.0,or is the Android Studio or the IDE up to date with Oreo.

Related

Why doesn't WebView see JavaScript and sometimes crashes?

I have a small app that tries to run WebView as follows:
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_photo_page, container, false);
mWebView = v.findViewById(R.id.web_view);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl(mUri.toString());
return v;
}
When i try to run it on an API 24 device that doesn't have google services the WebView works, but for some reason doesn't enable JavaScript, even though setJavaScriptEnabled(true) is used. When i try to perform the same on an API 24 device with google service, the WebView works well and can see JavaScript code. But the oddities don't end there...
In cases when i run the app on a devices that have API lower than 24 (i tried on 23 and 22) possession of google service doesn't influence JavaScript code processing by the WebView. In Either cases JavaScript doesn't work in the WebView for some reason.
API 25 has the same issues as 24 does.
API 26 bring something new. When i perform testing on a device with google services the works well. But without them the app just crashes while inflating writing to logcat the following:
E/WebViewFactory: Chromium WebView package does not exist
android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
at android.webkit.WebViewFactory.getWebViewContextAndSetProvider(WebViewFactory.java:334)
at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:398)
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:211)
at android.webkit.WebView.getFactory(WebView.java:2467)
at android.webkit.WebView.ensureProviderCreated(WebView.java:2462)
at android.webkit.WebView.setOverScrollMode(WebView.java:2527)
at android.view.View.<init>(View.java:4536)
at android.view.View.<init>(View.java:4668)
at android.view.ViewGroup.<init>(ViewGroup.java:597)
at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
at android.webkit.WebView.<init>(WebView.java:636)
at android.webkit.WebView.<init>(WebView.java:581)
at android.webkit.WebView.<init>(WebView.java:564)
at android.webkit.WebView.<init>(WebView.java:551)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.bignerdranch.android.photogallery.PhotoPageFragment.onCreateView(PhotoPageFragment.java:41)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3138)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3072)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:502)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:248)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1333)
at android.app.Activity.performStart(Activity.java:6992)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2780)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bignerdranch.android.photogallery, PID: 8470
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bignerdranch.android.photogallery/com.bignerdranch.android.photogallery.PhotoPageActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.webkit.WebView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.webkit.WebView
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.webkit.WebView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.bignerdranch.android.photogallery.PhotoPageFragment.onCreateView(PhotoPageFragment.java:41)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3138)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3072)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:502)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:248)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1333)
at android.app.Activity.performStart(Activity.java:6992)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2780)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
E/AndroidRuntime: Caused by: android.util.AndroidRuntimeException: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:438)
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:211)
at android.webkit.WebView.getFactory(WebView.java:2467)
at android.webkit.WebView.ensureProviderCreated(WebView.java:2462)
at android.webkit.WebView.setOverScrollMode(WebView.java:2527)
at android.view.View.<init>(View.java:4536)
at android.view.View.<init>(View.java:4668)
at android.view.ViewGroup.<init>(ViewGroup.java:597)
at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
at android.webkit.WebView.<init>(WebView.java:636)
at android.webkit.WebView.<init>(WebView.java:581)
at android.webkit.WebView.<init>(WebView.java:564)
at android.webkit.WebView.<init>(WebView.java:551)
... 35 more
Caused by: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
at android.webkit.WebViewFactory.getWebViewContextAndSetProvider(WebViewFactory.java:334)
at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:398)
... 47 more
On API 27 devices the WebView can see JavaScript even if there are no google services.
All tests was performed on Nexus 5X.
In cases when WebView doesn't process JavaScript i tried to add the following code:
webSettings.setDomStorageEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);
webSettings.setSupportZoom(true);
webSettings.setDefaultTextEncodingName("utf-8");
mWebView.setWebChromeClient(new WebChromeClient());
and also change the device to another one. Nothing of mentioned above fixed the problem.
So my questions are:
How google services impact possibility to see JavaScript for WebView ?
Why can't WebView be inflated in API 26. It is placed in android so i have to be able to inflate it. Isn't it so ?
And finally. How do i have to use WebView correctly so that it can see JavaScript and not get crashed across all API's ?
Before starting the Fragment or Activity, make sure that the WebView is installed or active.
public static boolean webViewEnabled() {
try {
return CookieManager.getInstance() != null;
} catch (Exception e) {
return false;
}
}
public static boolean appInstalledOrNot(String uri) {
PackageManager pm = ApplicationLoader.getContext().getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException ignored) {
}
return app_installed;
}
Checking if WebView is installed or active (you can even display a suitable response to the user:
if (!webViewEnabled()) {
if (appInstalledOrNot("com.google.android.webview")) {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", "com.google.android.webview", null);
intent.setData(uri);
startActivity(intent);
} else if (appInstalledOrNot("com.huawei.webview")) {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", "com.huawei.webview", null);
intent.setData(uri);
startActivity(intent);
} else if (appInstalledOrNot("com.android.vending")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage("com.android.vending");
intent.setData(Uri.parse("market://details?id=com.google.android.webview"));
startActivity(intent);
} else if (appInstalledOrNot("com.huawei.appmarket")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage("com.huawei.appmarket");
intent.setData(Uri.parse("appmarket://details?id=com.huawei.webview"));
startActivity(intent);
} else {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.google.android.webview"));
try {
startActivity(intent);
} catch (Exception exception) {
//
}
}
} else {
// startActivity(new Intent(this, WebViewActivity.class)) or ...
}

My app to know if a file exist in a URL keeps stoping [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
Im trying to write an app that puts a string in a textview if there is a file in a given url, this is the code and the crash info, what could be the error?.
public class MainActivity extends AppCompatActivity {
String url = "https://images.pexels.com/photos/617278/pexels-photo-617278.jpeg?cs=srgb&dl=adorable-animal-blur-617278.jpg&fm=jpg";
TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView.findViewById(R.id.textView);
try {
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod("HEAD");
connection.connect();
if(connection.getResponseCode() == HttpURLConnection.HTTP_OK){
textView.setText("File Exists!!");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.archivoexiste, PID: 6160
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.archivoexiste/com.example.android.archivoexiste.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.widget.TextView.findViewById(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.widget.TextView.findViewById(int)' on a null object reference
at com.example.android.archivoexiste.MainActivity.onCreate(MainActivity.java:23)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6541) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
Application terminated.
Change this line in your oncreate method
textView.findViewById(R.id.textView);
to this
textView = (TextView) findViewById(R.id.textView);

What cause the exception ' java.lang.RuntimeException: Failed to call observer method'?

I am writing code to fetch data from a firebase database:
private void displayMessages(){
//Suppose you want to retrieve "chats" in your Firebase DB:
DatabaseReference ref=FirebaseDatabase.getInstance().getReference(Constants.USERS_CHAT).child(chatId);
Log.d(TAG,"Inside query"+ref);
ref.addListenerForSingleValueEvent(new ValueEventListener(){
#Override
public void onDataChange(DataSnapshot dataSnapshot){
Log.d(TAG,"Inside query Inside onDataChange");
if(dataSnapshot.exists()) {
queryforDisplayMessages=mDbRefusers_chat.child(chatId);
}else{
queryforDisplayMessages=mDbRefusers_chat.child(revchatId);
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
But when running it, I get the following exception:
Process: com.iworld.daxi, PID: 20438
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.iworld.daxi/com.iworld.daxi.UserChatActivity}:
java.lang.RuntimeException: Failed to call observer method
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6809)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.RuntimeException: Failed to call observer method
at android.arch.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:225)
at android.arch.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:193)
at android.arch.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:184)
at android.arch.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:36)
at android.arch.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
at android.arch.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:292)
at android.arch.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:332)
at android.arch.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:137)
at android.arch.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:123)
at android.arch.lifecycle.ReportFragment.dispatch(ReportFragment.java:121)
at android.arch.lifecycle.ReportFragment.onStart(ReportFragment.java:81)
at android.app.Fragment.performStart(Fragment.java:2637)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1312)
at android.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1549)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1611)
at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3039)
at android.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:2996)
at android.app.FragmentController.dispatchStart(FragmentController.java:189)
at android.app.Activity.performStart(Activity.java:7021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2909)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6809) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.database.ChildEventListener com.google.firebase.database.Query.addChildEventListener(com.google.firebase.database.ChildEventListener)' on a null object reference
at com.firebase.ui.database.FirebaseArray.onCreate(FirebaseArray.java:53)
at com.firebase.ui.common.BaseObservableSnapshotArray.addChangeEventListener(BaseObservableSnapshotArray.java:97)
at com.firebase.ui.database.FirebaseListAdapter.startListening(FirebaseListAdapter.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at android.arch.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:215)
at android.arch.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:193) 
at android.arch.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:184) 
at android.arch.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:36) 
at android.arch.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354) 
at android.arch.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:292) 
at android.arch.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:332) 
at android.arch.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:137) 
at android.arch.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:123) 
at android.arch.lifecycle.ReportFragment.dispatch(ReportFragment.java:121) 
at android.arch.lifecycle.ReportFragment.onStart(ReportFragment.java:81) 
at android.app.Fragment.performStart(Fragment.java:2637) 
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1312) 
at android.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1549) 
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1611) 
at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3039) 
at android.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:2996) 
at android.app.FragmentController.dispatchStart(FragmentController.java:189) 
at android.app.Activity.performStart(Activity.java:7021) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2909) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6809) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
03-08 10:22:40.020 20438-20438/com.iworld.daxi D/AppTracker: App Event: crash
I have also observed that the onDataChange() method is not getting triggered.

"You must pass in a non null View" when trying to get Facebook profile picture to ImageView

I'm using Firebase Facebook auth and trying to fetch profile picture to menu ImageView tried everything but it says same thing.
This is the Code in HomeScreen.java that has menu in it, And my Login is in MainScreen.java if you need other codes please let me know.
public class HomeScreen extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mToggle;
private Toolbar mToolbar;
private CircleImageView mProfile;
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.MyNavTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_screen);
mToolbar = (Toolbar) findViewById(R.id.nav_actionbar);
setSupportActionBar(mToolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.opendrawer, R.string.closedrawer);
mDrawerLayout.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
/**-------------------Facebook Profile Picture-----------------------*/
mProfile = (CircleImageView) findViewById(R.id.ivProfile);
int dimensionPixelSize = getResources().getDimensionPixelSize(com.facebook.R.dimen.com_facebook_profilepictureview_preset_size_large);
Uri profilePictureUri= Profile.getCurrentProfile().getProfilePictureUri(dimensionPixelSize , dimensionPixelSize);
Glide.with(this).load(profilePictureUri)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(mProfile);
}
ImageView I'm trying to put it in
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/ivProfile"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
app:civ_border_width="2dp"
app:civ_border_color="#FFFFFF"/>
Error:
08-02 11:04:46.791 22863-22863/com.shopfolio.shopfolio E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.shopfolio.shopfolio, PID: 22863
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shopfolio.shopfolio/com.shopfolio.shopfolio.HomeScreen}: java.lang.IllegalArgumentException: You must pass in a non null View
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6540)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalArgumentException: You must pass in a non null View
at com.bumptech.glide.GenericRequestBuilder.into(GenericRequestBuilder.java:678)
at com.bumptech.glide.DrawableRequestBuilder.into(DrawableRequestBuilder.java:448)
at com.shopfolio.shopfolio.HomeScreen.onCreate(HomeScreen.java:56)
at android.app.Activity.performCreate(Activity.java:6980)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6540) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
08-02 11:04:46.791 22863-22863/com.shopfolio.shopfolio E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shopfolio.shopfolio/com.shopfolio.shopfolio.HomeScreen}: java.lang.IllegalArgumentException: You must pass in a non null View
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6540)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalArgumentException: You must pass in a non null View
at com.bumptech.glide.GenericRequestBuilder.into(GenericRequestBuilder.java:678)
at com.bumptech.glide.DrawableRequestBuilder.into(DrawableRequestBuilder.java:448)
at com.shopfolio.shopfolio.HomeScreen.onCreate(HomeScreen.java:56)
at android.app.Activity.performCreate(Activity.java:6980)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6540) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
Sorry if it's not clear enough

Not able to modify Cordova WebView

I'm developing Cordova application with EmberJs. There I require to local ajax calls, i.e, ajax call to file:/// url. Cordova doesn't allow that. So I found that I need to modify Cordova WebView settings. For that, I tried this code:
import android.os.Build;
import android.os.Bundle;
import org.apache.cordova.*;
import org.apache.cordova.engine.SystemWebView;
import android.webkit.WebSettings;
public class MainActivity extends CordovaActivity
{
SystemWebView webView = null;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set by <content src="index.html" /> in config.xml
webView = (SystemWebView) appView.getView();
WebSettings settings = webView.getSettings();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
settings.setAllowFileAccessFromFileURLs(true);
settings.setAllowUniversalAccessFromFileURLs(true);
}
loadUrl(launchUrl);
}
}
But I'm always getting following error:
Runtime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.scb.prototype/com.scb.prototype.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'android.view.View org.apache.cordova.CordovaWebView.getView()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
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.NullPointerException: Attempt to invoke interface method 'android.view.View org.apache.cordova.CordovaWebView.getView()' on a null object reference
at com.scb.prototype.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
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) 
appView is returning null. Any solution for this?
If anyone can suggest how to allow ajax from file:/// url in Cordova, that will also resolve my issue.
Thanks in advance.
You are getting NullPointerException because super.init() is not called and your appView is not initialized.
SystemWebView webView = null;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
// Set by <content src="index.html" /> in config.xml
webView = (SystemWebView) appView.getEngine().getView();
WebSettings settings = webView.getSettings();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
settings.setAllowFileAccessFromFileURLs(true);
settings.setAllowUniversalAccessFromFileURLs(true);
}
loadUrl(launchUrl);
}

Categories

Resources