setDropDownBackgroundResource not working in marshmallows android - android

i have try to set the dropdown color for the autocomplete text view it works fine in all other api but when ever i run it with the nexus 5 marshmallows i got the following error
my log cat is
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: FATAL EXCEPTION: main
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: Process: test.text.com, PID: 29058
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.support.v7.internal.widget.TintManager.getDrawable(int)' on a null object reference
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: at android.support.v7.widget.AppCompatAutoCompleteTextView.setDropDownBackgroundResource(AppCompatAutoCompleteTextView.java:96)
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: at test.text.com.activity.CreateRideActivity.onWindowFocusChanged(CreateRideActivity.java:369)
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: at android.support.v7.internal.view.WindowCallbackWrapper.onWindowFocusChanged(WindowCallbackWrapper.java:114)
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: at android.support.v7.internal.view.WindowCallbackWrapper.onWindowFocusChanged(WindowCallbackWrapper.java:114)
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: at com.android.internal.policy.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:3237)
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: at android.view.View.dispatchWindowFocusChanged(View.java:9528)
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:1200)
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3378)
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
11-02 17:36:23.815 29058-29058/test.text.com E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
My code is
AutoSuggestView.setDropDownBackgroundResource(R.drawable.bg_rectangle_white_curve_border_right);

Try to update your appcompat libraries. In the current (23.1.1) version of appcompat-v7 the code in AppCompatAutoCompleteTextView was changed to resolve this like so
public void setDropDownBackgroundResource(#DrawableRes int resId) {
if (mTintManager != null) {
setDropDownBackgroundDrawable(mTintManager.getDrawable(resId));
} else {
super.setDropDownBackgroundResource(resId);
}
}

Related

Reminders app tutorial, app does not load, issue with java file

I am learning Android Studio from a book called "Learn Android Studio: Build Android Apps Quickly and Effectively" By: Clifton Craig; Adam Gerber. I am following a tutorial on how to build a Reminders app and can't get the app to load. In the tutorial, I have been instructed to alter the onCreate() method with what is provided in the book, making sure to import what they provided.
The altered code is provided here.
The logcat is provided below:
01-18 06:04:55.460 2212-2212/com.apress.gerber.reminders I/art: Not late-enabling -Xcheck:jni (already on)
01-18 06:04:55.800 2212-2212/com.apress.gerber.reminders W/System: ClassLoader referenced unknown path: /data/app/com.apress.gerber.reminders-2/lib/x86_64
01-18 06:04:55.960 2212-2212/com.apress.gerber.reminders D/AndroidRuntime: Shutting down VM
01-18 06:04:55.960 2212-2212/com.apress.gerber.reminders E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.apress.gerber.reminders, PID: 2212
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apress.gerber.reminders/com.apress.gerber.reminders.RemindersActivity}: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.ListView
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.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.ListView
at com.apress.gerber.reminders.RemindersActivity.onCreate(RemindersActivity.java:22)
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)
01-18 06:05:00.980 2212-2212/com.apress.gerber.reminders I/Process: Sending signal. PID: 2212 SIG: 9
The app will not load. The emulator gives an error. Any feedback on this would be greatly appreciated.

Java.lang.IllegalStateException Activity has been destroyed

I know there are lots of same question and I checked its solutions\ suggestions. However, they are not working for me. I am trying to add fragment and when I am calling fragmentTransaction.commit() it throws that exception, but that happens only with my 2nd fragment.
I send a notification to my application, when it is clicked, it opens my app which open main fragment, at that time getSupportFragmentManager().findFragmentById(R.id.rl_content_fragment); returns null for current fragment ( which should be correct ), problem is my 2nd fragment ( playerFragment) when I try to add it ( while debugging) I found out that getSupportFragmentManager() still returns null for current fragment and it throws the exception that the activity has been destroyed when I call fragmentTransaction.commit().
My questions
1-is why does the Activity gets destroyed or finish while the application is starting?
2-how can I fix that issue?
Any hint will be appreciated, thanks.
EDIT this is the exception which I get, I know I should not change views unless I am on mainThread, but I do report on main thread, Sorry forgot to say we are using commitAllowingStateLoss() and this what i get
java.lang.IllegalStateException: Activity has been destroyed
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1399)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:637)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:620)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at com.myApp.BaseActivity.addContentFragment(BaseActivity.java:502)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at com.myApp.BaseActivity$3.onCompleted(BaseActivity.java:837)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at com.myAppSDK.Managers.SignalManager.setCompleted(SignalManager.java:291)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at com.myAppSDK.Managers.EpisodeManager$5.onCompleted(EpisodeManager.java:1107)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at com.myAppSDK.Managers.SignalManager.setCompleted(SignalManager.java:291)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at com.myAppSDK.Managers.APIRequestManager$ConnectionTask.onPostExecute(APIRequestManager.java:645)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at com.myAppSDK.Managers.APIRequestManager$ConnectionTask.onPostExecute(APIRequestManager.java:546)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at android.os.AsyncTask.finish(AsyncTask.java:632)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at android.os.AsyncTask.access$600(AsyncTask.java:177)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5146)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
and if i use commit() I get this exception
Process: com.myApp, PID: 10659
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1377)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1395)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:637)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:616)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at com.myApp.BaseActivity.addContentFragment(BaseActivity.java:502)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at com.myApp.BaseActivity$3.onCompleted(BaseActivity.java:837)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at com.myAppSDK.Managers.SignalManager.setCompleted(SignalManager.java:291)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at com.myAppSDK.Managers.EpisodeManager$5.onCompleted(EpisodeManager.java:1107)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at com.myAppSDK.Managers.SignalManager.setCompleted(SignalManager.java:291)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at com.myAppSDK.Managers.APIRequestManager$ConnectionTask.onPostExecute(APIRequestManager.java:645)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at com.myAppSDK.Managers.APIRequestManager$ConnectionTask.onPostExecute(APIRequestManager.java:546)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at android.os.AsyncTask.finish(AsyncTask.java:632)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at android.os.AsyncTask.access$600(AsyncTask.java:177)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5146)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
sorry for much logs

How to access packages created in android studio?

I am new to android and stuck at point. Please help!
I have created a dummy Hello world program (with project name testneha) in android studio. I created a new package "AppTest" folder inside the "com.example.ospune.testneha" folder. Inside the package, have created a JAVA class file with name AppTest1.
Folder Structure
com.example.ospune.test
AppTest(package folder)
AppTest1(java file)
MainActivity(file)
In AppTest1 file, onCreate folder I am calling "apptest layout file".
Now In the mainActivity file, I have added a button; which on being clicked calls startActivity mentioned in the AppTest1 class.
public void sendMessage(View view)
{
Intent intent = new Intent(this, com.example.ospune.test.neha.AppTest.AppTest1.class");
startActivity(intent);
}
My problem is when I click the button, I get a pop up saying "unfortunately, Test has stopped."
AndroidManifest.xml was also updated with the AppTest1.class activity
<activity
android:name=".AppTest.AppTest1"
android:parentActivityName=".MainActivity"
</activity>
I am clueless as what is the reason for this :(
LogCat error -
11-03 04:34:43.409 2055-2055/com.example.ospunelap_130.testneha I/art: Not late-enabling -Xcheck:jni (already on)
11-03 04:34:43.410 2055-2055/com.example.ospunelap_130.testneha I/art: Late-enabling JIT
11-03 04:34:43.419 2055-2055/com.example.ospunelap_130.testneha I/art: JIT created with code_cache_capacity=2MB compile_threshold=1000
11-03 04:34:43.507 2055-2055/com.example.ospunelap_130.testneha W/System: ClassLoader referenced unknown path: /data/app/com.example.ospunelap_130.testneha-2/lib/x86
11-03 04:34:43.914 2055-2083/com.example.ospunelap_130.testneha D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
11-03 04:34:43.918 2055-2055/com.example.ospunelap_130.testneha D/: HostConnection::get() New Host Connection established 0xad7f0110, tid 2055
11-03 04:34:44.008 2055-2083/com.example.ospunelap_130.testneha D/: HostConnection::get() New Host Connection established 0xad7f0420, tid 2083
11-03 04:34:44.033 2055-2083/com.example.ospunelap_130.testneha I/OpenGLRenderer: Initialized EGL, version 1.4
11-03 04:34:44.145 2055-2083/com.example.ospunelap_130.testneha W/EGL_emulation: eglSurfaceAttrib not implemented
11-03 04:34:44.145 2055-2083/com.example.ospunelap_130.testneha W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xabebf2c0, error=EGL_SUCCESS
11-03 04:34:45.360 2055-2055/com.example.ospunelap_130.testneha I/Choreographer: Skipped 66 frames! The application may be doing too much work on its main thread.
11-03 04:35:03.158 2055-2055/com.example.ospunelap_130.testneha D/AndroidRuntime: Shutting down VM
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: FATAL EXCEPTION: main
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: Process: com.example.ospunelap_130.testneha, PID: 2055
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ospunelap_130.testneha/com.example.ospunelap_130.testneha.AppTest.AppTest1}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.support.v7.widget.Toolbar.getTitle()' on a null object reference
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.support.v7.widget.Toolbar.getTitle()' on a null object reference
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.support.v7.internal.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:100)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.support.v7.internal.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:93)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.support.v7.internal.app.ToolbarActionBar.<init>(ToolbarActionBar.java:78)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:206)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:99)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at com.example.ospunelap_130.testneha.AppTest.AppTest1.onCreate(AppTest1.java:22)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6237)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java) 
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148) 
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417) 
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
11-03 04:35:03.159 2055-2055/com.example.ospunelap_130.testneha E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
11-03 04:35:07.335 2055-2055/com.example.ospunelap_130.testneha I/Process: Sending signal. PID: 2055 SIG: 9
EDIT:
The error is due to invoking toolbar.getTitle() method. The toolbar object is returning null. Try this:
Toolbar toolbar = (Toolbar) findviewById(R.id.toolbar);
to initialize the toolbar. The error is at line no. 22 according to logcat.

Error Loading Static Fragment and a FrameLayout (

I'm trying to load layout with a static fragment and a LinearLayout using this Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
tools:context="com.eldad.yossi.popularmovs.MainActivity">
<fragment
android:id="#+id/main_fragment"
android:name="com.eldad.yossi.popularmovs.MainActivityFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
tools:layout="#android:layout/list_content" />
<FrameLayout
android:id="#+id/movies_detail_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4" />
</LinearLayout>
But when the app is launched I get this error:
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: FATAL EXCEPTION: ModernAsyncTask #2
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: Process: com.eldad.yossi.popularmovs, PID: 13809
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: java.lang.RuntimeException: An error occurred while executing doInBackground()
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.ModernAsyncTask$3.done(ModernAsyncTask.java:142)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:242)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.lang.Thread.run(Thread.java:818)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getScheme()' on a null object reference
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1437)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.content.ContentResolver.query(ContentResolver.java:462)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.ContentResolverCompatJellybean.query(ContentResolverCompatJellybean.java:29)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.ContentResolverCompat$ContentResolverCompatImplJB.query(ContentResolverCompat.java:57)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.ContentResolverCompat.query(ContentResolverCompat.java:125)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:59)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:37)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:296)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:54)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:42)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.ModernAsyncTask$2.call(ModernAsyncTask.java:128)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.lang.Thread.run(Thread.java:818) 
The same Activity and fragments work when I'm loading them using a layout that contain only the fragment.
any ideas?
The full code is in a GitHub repo - https://github.com/yossildad/PopularMovs
Thanks.
From the stack trace I could see you are trying to get an URI from a null reference in the doInBackground() method in activity com.eldad.yossi.popularmovs.MainActivity .
Ok, I've found the bug. I was using a not initialized uri when creating the Loader
inside the fragment.
Thanks for your help and sorry for the trouble.
Your problem is not in the fragment declaration. According to the stacktrace, look into the doInBackground method of your ModernASyncTask which you are extends on.
java.lang.RuntimeException: An error occurred while executing doInBackground() - probably you may have null reference on a context object, i guess.

Contacts List Read Permission Error in Android

As you can tell I am a newbie to Android :) and struggling with retrieving contacts list. I did add android.permission.READ_CONTACTS in AndroidManifest.xml but still it is not working. I am running it on Windows 10, in case if that makes any difference. Thanks in advance.
09-07 17:27:15.819 5272-5272/? I/art﹕ Not late-enabling -Xcheck:jni (already on)
09-07 17:27:15.819 5272-5272/? I/art﹕ Late-enabling JIT
09-07 17:27:15.821 5272-5272/? I/art﹕ JIT created with code_cache_capacity=2MB compile_threshold=1000
09-07 17:27:15.871 5272-5272/com.sr.phonecontactslist W/System﹕ ClassLoader referenced unknown path: /data/app/com.sr.phonecontactslist-1/lib/x86
09-07 17:27:15.879 5272-5272/com.sr.phonecontactslist D/AndroidRuntime﹕ Shutting down VM
09-07 17:27:15.879 5272-5272/com.sr.phonecontactslist E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.sr.phonecontactslist, PID: 5272
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sr.phonecontactslist/com.sr.phonecontactslist.MainActivity}: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{15540fd 5272:com.sr.phonecontactslist/u0a59} (pid=5272, uid=10059) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
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.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{15540fd 5272:com.sr.phonecontactslist/u0a59} (pid=5272, uid=10059) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3550)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4778)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2018)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1468)
at android.content.ContentResolver.query(ContentResolver.java:475)
at android.content.ContentResolver.query(ContentResolver.java:434)
at com.sr.phonecontactslist.MainActivity.onCreate(MainActivity.java:20)
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)

Categories

Resources