IllegalArgumentException: No view found for id - on app restart - android

My app is built using fragments and the v4 support fragment manager. The app works well from startup and in fact I can't recreate this bug myself, so in principle the structure of my xml is fine. However my crash reports are indicating a lot of users are getting a crash when returning to the app, resuming it after a pause. I get:
IllegalArgumentException: No view found for id 0x7f06002d
Please refer to my XML below. The id reported as not found can vary, it can be any one of the nested RelativeLayouts. Why are these views disappearing/not found, randomly?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F7F5F5"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/menuLayout"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_above="#+id/bottomFragmentLayout"
android:layout_alignParentLeft="true"
android:visibility="visible" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/whenLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_above="#+id/bottomFragmentLayout"
android:layout_toRightOf="#+id/menuLayout"
android:visibility="invisible" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/howLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_above="#+id/bottomFragmentLayout"
android:layout_toRightOf="#+id/menuLayout"
android:visibility="invisible" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/whereLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottomFragmentLayout"
android:layout_toRightOf="#+id/menuLayout"
android:visibility="invisible" >
</RelativeLayout>
<!-- The bottom bar -->
<RelativeLayout
android:id="#+id/bottomFragmentLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#999999" >
</RelativeLayout>
</RelativeLayout>
Edit: Full stack trace:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.android/com.myapp.android.activity.MainFragmentActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f060030 (com.myapp.android:id/howLayout) for fragment WhatFragment{4220b058 #4 id=0x7f060030 WhatFragment}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3692)
at android.app.ActivityThread.access$700(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1240)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f060030 (com.myapp.android:id/howLayout) for fragment WhatFragment{4220b058 #4 id=0x7f060030 WhatFragment}
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:919)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
at com.myapp.android.activity.MainFragmentActivity.onStart(MainFragmentActivity.java:449)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1164)
at android.app.Activity.performStart(Activity.java:5114)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3692)
at android.app.ActivityThread.access$700(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1240)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(NativeStart.java)

// try this way
1. when you gave other layout reference like android:layout_above="#+id/bottomFragmentLayout" so here "+" sign removed from reference "+" is for new id declaration so we not declare new id but just gave already define id reference.
2. in your xml define bottom layout at last and try using this layout id before bottom layout declaration that y it's not finding such kind of layout so you have decalre first layout then gave reference as another layouyt which i correct in my ans.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F7F5F5"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/bottomFragmentLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#999999" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/menuLayout"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_above="#id/bottomFragmentLayout"
android:layout_alignParentLeft="true"
android:visibility="visible" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/whenLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_above="#id/bottomFragmentLayout"
android:layout_toRightOf="#id/menuLayout"
android:visibility="invisible" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/howLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_above="#id/bottomFragmentLayout"
android:layout_toRightOf="#id/menuLayout"
android:visibility="invisible" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/whereLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/bottomFragmentLayout"
android:layout_toRightOf="#id/menuLayout"
android:visibility="invisible" >
</RelativeLayout>
</RelativeLayout>

Related

Dialog view must contain an EditText with id #android:id/edit

I'm using support:preference-v7:25.0.1 and in my app I'm using an PreferenceActivity to set username with an EditText. When I run my app, at runtime I get the following error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: it.company.android.aaaa, PID: 8023
java.lang.IllegalStateException: Dialog view must contain an EditText with id #android:id/edit
at android.support.v7.preference.EditTextPreferenceDialogFragmentCompat.onBindDialogView(EditTextPreferenceDialogFragmentCompat.java:67)
at android.support.v7.preference.PreferenceDialogFragmentCompat.onCreateDialog(PreferenceDialogFragmentCompat.java:148)
at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:312)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1682)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:541)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5633)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:896)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)
at dalvik.system.NativeStart.main(Native Method)
Why I get this error? How can I resolve this problem?
Thank you to all.
Sadly, this is a mistake on Google and I have filed a bug issue
https://code.google.com/p/android/issues/detail?id=231576
The hack to get around this in the mean time is to:
Create this layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:layout_marginBottom="48dp"
android:overScrollMode="ifContentScrolls">
<LinearLayout
android:id="#+id/edittext_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:orientation="vertical">
<EditText
android:id="#android:id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="4dp"
android:paddingEnd="4dp" />
</LinearLayout>
</ScrollView>
Then after you create your object (EditTextPreference editTextPreference = new EditTextPreference(context)), call setDialogLayoutResource(R.layout.THE_LAYOUT_ABOVE);
This will resolve the issue for now

ClassCastException from View objects in android studio

In Android Studio, when i try to run my project i get a ClassCastException as following:
Caused by: java.lang.ClassCastException: android.widget.EditText cannot be cast to android.widget.RelativeLayout
when the View object is 100% RelativeLayout and not EditText.
The problem occurs on another View element if i comment out the above-related code..
I have tried cleaning and rebuilding the project, i have tried editing the XML file and change the ID, i have tried deleting the XML file and restarting Android Studio and then make a new XML file, all that to no avail.
Thank you for your help.
EDIT
When i add new views to the xml, with id that i never used, somehow the activity before it gets nulls on its own (and totally seperate) xml file.. this is weird because theres no reason why a simple view on a different xml file should impact another xml that is loaded even before it..
EDIT2
I inspected View rl = activityView.findViewById(R.id.notification); and found out that it gets etMessage which is another view element in the same XML and is infact an EditText type view.
The code before the exception occurs:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setInitialView();
}
private void setInitialView() {
RelativeLayout frame = (RelativeLayout) findViewById(R.id.activity_frame);
LayoutInflater layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View activityView = layoutInflater.inflate(R.layout.chat, null,false);
frame.removeAllViews();
frame.addView(activityView);
chatMap.put("Public", new ArrayList<ChatMessageBox>());
// move the notification layout outside the screen
RelativeLayout rl = (RelativeLayout) findViewById(R.id.notification);
TranslateAnimation moveAnim = new TranslateAnimation(
TranslateAnimation.ABSOLUTE, 0, TranslateAnimation.ABSOLUTE, 0,
TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, -1);
moveAnim.setDuration(0);
moveAnim.setFillAfter(true);
rl.startAnimation(moveAnim);
}
This activity's parent XML, which is loaded with setContentView in its onCreate:
<?xml version="1.0" encoding="utf-8"?>
<!-- Making the drawer layout the root view -->
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- MAIN CONTENT -->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</RelativeLayout>
<!-- The ListView to be displayed when the drawer layout is active -->
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
And the XML that has the appropriate view:
<?xml version="1.0" encoding="utf-8"?>
<!-- Making the drawer layout the root view -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:id="#+id/chat_relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ScrollView
android:id="#+id/scroller"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_above="#+id/bSendMessage"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#drawable/chat_bg" >
<LinearLayout
android:id="#+id/chatWindowContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/bSendMessage"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/ic_send" />
<EditText
android:id="#+id/etMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/bSendMessage"
android:layout_toLeftOf="#+id/bSendMessage"
android:paddingLeft="10dp"
android:background="#drawable/text"
android:textColor="#000000"
android:imeOptions="actionNone"
android:inputType="textMultiLine"
android:maxLines="4"
android:singleLine="true"
android:layout_alignParentRight="false"
android:layout_alignWithParentIfMissing="false" />
<!-- the desired element -->
<RelativeLayout
android:id="#+id/notification"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/bg_upload"
>
<TextView
android:id="#+id/tvNotification"
android:layout_gravity="center"
android:text="New Message Recieved"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textColor="#000000" />
</RelativeLayout>
</RelativeLayout>
Error log:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.raad/com.example.raad.activities.ChatActivity}: java.lang.ClassCastException: android.widget.EditText cannot be cast to android.widget.RelativeLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
at android.app.ActivityThread.access$600(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: android.widget.EditText cannot be cast to android.widget.RelativeLayout
at com.example.raad.activities.ChatActivity.setInitialView(ChatActivity.java:336)
at com.example.raad.activities.ChatActivity.onCreate(ChatActivity.java:43)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403) 
at android.app.ActivityThread.access$600(ActivityThread.java:165) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:194) 
at android.app.ActivityThread.main(ActivityThread.java:5391) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 
at dalvik.system.NativeStart.main(Native Method)
The problem was probably with the cache of the application in the device itself.
I ran the application on a different device and there was no issue, so i cleared the data and cache from the device (Settings -> Apps) and uninstalled the app (just uninstalling didnt work), and now it works.
Change your onCreate like this:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourLayoutXmlName);
setInitialView();
}
Edit:
Try changing this line:
RelativeLayout rl = (RelativeLayout) findViewById(R.id.notification);
to
RelativeLayout rl = (RelativeLayout) activityView.findViewById(R.id.notification);
Hope it helps you.
R.id.activity_frame
does not exists in your xml file. Try to resolve this.
And post the complete code.

Butterknife Nullpointer exception in android 4.2

Using Butterknife in my current project; it works fine on Kitkat and lollipop but throws a nullpointer exception on jellybean (4.2).
Exception is thrown at this line (btnLogin is NULL)
btnLogin.setTypeface(FontsHelper.robotoRegular(this));
Activity Code
public class Login extends Activity {
#Bind(R.id.btnLogin)
FButton btnLogin;
#Bind(R.id.btnRegister)
FButton btnRegister;
#Bind(R.id.edtEmail)
EditText edtEmail;
#Bind(R.id.edtPassword)
EditText edtPassword;
#Bind(R.id.rlProgress)
RelativeLayout rlProgress;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
System.out.println("Binding password" + edtPassword); //prints null
System.out.println("Binding "+btnLogin); //prints null
btnLogin.setTypeface(FontsHelper.robotoRegular(this));
}
}
The layout....
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="vertical"
android:gravity="center">
<ImageView android:id="#+id/imageView1" android:layout_width="wrap_content"
android:layout_height="0dp" android:src="#drawable/lm_logo_with_text"
android:layout_weight="0.5" android:paddingLeft="#dimen/pad_40dp"
android:paddingRight="#dimen/pad_40dp"
android:gravity="center_horizontal|center_vertical"/>
<LinearLayout android:id="#+id/llContent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_weight="0.5"
android:orientation="vertical" android:paddingLeft="#dimen/pad_40dp" android:paddingRight="#dimen/pad_40dp">
<EditText android:id="#+id/edtEmail" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:hint="Email"
android:drawableLeft="#drawable/ic_email" android:inputType="textEmailAddress" style="#style/txt_white">
<requestFocus />
</EditText>
<View android:background="#color/gray"
android:layout_width="fill_parent" android:layout_height="#dimen/divider" android:layout_marginTop="#dimen/pad_16dp" />
<EditText android:id="#+id/edtPassword" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:hint="Password"
android:drawableLeft="#drawable/ic_pwd" android:inputType="textPassword" style="#style/txt_white" />
<View android:background="#color/gray"
android:layout_width="fill_parent" android:layout_height="#dimen/divider" />
<View android:background="#color/gray"
android:layout_width="fill_parent" android:layout_height="#dimen/divider" android:layout_marginTop="#dimen/pad_16dp"
android:visibility="gone"/>
<EditText android:id="#+id/edtEmailUnused" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:hint="Email address"
android:drawableLeft="#drawable/ic_pwd" android:inputType="textEmailAddress" style="#style/txt_white"
android:visibility="gone"/>
<info.hoang8f.widget.FButton
android:layout_width="fill_parent" android:layout_height="50dp"
android:id="#+id/btnLogin"
android:textColor="#color/white"
fbutton:buttonColor="#color/picton_blue"
fbutton:shadowColor="#color/san_marino"
fbutton:shadowEnabled="true"
fbutton:shadowHeight="2dp"
fbutton:cornerRadius="2dp"
android:text="Login"
android:layout_marginBottom="#dimen/pad_10dp"
android:layout_marginTop="#dimen/pad_40dp"
android:padding="#dimen/pad_15dp"
/>
<info.hoang8f.widget.FButton
android:layout_width="fill_parent" android:layout_height="50dp"
android:id="#+id/btnRegister"
android:textColor="#color/white"
fbutton:buttonColor="#color/niagara"
fbutton:shadowColor="#color/san_marino"
fbutton:shadowEnabled="true"
fbutton:shadowHeight="2dp"
fbutton:cornerRadius="2dp"
android:text="Register"
android:layout_marginBottom="#dimen/pad_40dp"
android:layout_marginTop="#dimen/pad_5dp"
android:padding="#dimen/pad_15dp"
android:onClick="gotoHome"
/>
<Button android:id="#+id/btnFb" android:background="#drawable/btn_fb"
android:layout_width="fill_parent" android:layout_height="wrap_content" style="#style/btn" android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/rlProgress"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white_45_percent"
android:clickable="true"
android:animateLayoutChanges="true"
android:visibility="gone"
xmlns:wheel="http://schemas.android.com/apk/res-auto">
<com.pnikosis.materialishprogress.ProgressWheel
android:id="#+id/progress_wheel"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
wheel:matProg_barColor="#555588FF"
wheel:matProg_progressIndeterminate="true" />
</RelativeLayout>
Stack trace
java.lang.RuntimeException: Unable to start activity ComponentInfo{lifemedico.array.com.lifemedico/lifemedico.array.com.lifemedico.ui.login.Login}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at lifemedico.array.com.lifemedico.ui.login.Login.onCreate(Login.java:52)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
... 11 more
java.lang.NullPointerException
at lifemedico.array.com.lifemedico.ui.login.Login.onCreate(Login.java:52)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
There are no issues what so ever on lollipop and kitkat, but the debug statements both print null in jelly bean. Can't think of any reasons this is failing, any help is highly appreciated.
Thanks
Edit:
Adding debug option to butterknife gave me this
Not found. Trying superclass android.support.v7.app.ActionBarActivityd
MISS: Reached framework class. Abandoning search.
Some search online pointed to proguard, but i am not using proguard and this is still a debug version.
Guess i was looking down the wrong hole; there is no programming/syntax/logic error. As i have mentioned i looked into proguard and realized my gradle has multiDexEnabled; and for some reason Butterknife functions are stripped out. All i had to do is set my App to extend MultiDexApplication and it worked like a charm; took me a day to figure it out.
public class App extends MultiDexApplication {
I found a lead in this post https://github.com/JakeWharton/butterknife/issues/311
this issue can be resolved by updating your gradle file as mention by Butterknife on their gitgub
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
}
For exact reference you can refer link https://github.com/JakeWharton/butterknife
Please make your fields public i.e.:
#Bind(R.id.btnLogin)
public FButton btnLogin;
#Bind(R.id.btnRegister)
public FButton btnRegister;
#Bind(R.id.edtEmail)
public EditText edtEmail;
#Bind(R.id.edtPassword)
public EditText edtPassword;
#Bind(R.id.rlProgress)
public RelativeLayout rlProgress;
Butterknife cannot bind private variables, so make it public

Same code works on phisical device but not in the Android 4 emulator

My app is already using the Google Maps Android API v2 and it is working on my Galaxy Mini (Android 2.3.6). When I try to test in on an emulator using Platform 4.0.3, API level 15 and Google APIs, a get the following error:
01-23 14:26:31.581: ERROR/AndroidRuntime(688): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.remotepark/br.com.remotepark.activities.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:119)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at br.com.remotepark.activities.MainActivity.onCreate(MainActivity.java:51)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
... 11 more
Caused by: java.lang.NullPointerException
at br.com.remotepark.fragments.MapFragment.initLocation(MapFragment.java:86)
at br.com.remotepark.fragments.MapFragment.onCreateView(MapFragment.java:62)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:845)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1058)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1156)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:270)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
... 22 more
The line that throws the exception is this:
mMap.setInfoWindowAdapter(new MapInfoWindowAdapter(getLayoutInflater(savedInstanceState)));
The MapInfoWindowAdapter constructor is like this:
MapInfoWindowAdapter(LayoutInflater layoutInflater) {
mLayoutInflater = layoutInflater;
mWindow = mLayoutInflater.inflate(R.layout.map_info_window, null);
mContents = mLayoutInflater.inflate(R.layout.map_info_window, null);
}
And the map_info_window.xml is:
<ImageView
android:layout_width="40dip"
android:layout_height="40dip"
android:src="#drawable/ic_remote_park"
android:id="#+id/remotepark_logo"
android:layout_marginLeft="0dip"
android:layout_marginRight="8dip"
android:layout_marginTop="16dip"></ImageView>
<LinearLayout
android:id="#+id/balloon_inner_layout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:paddingTop="5dip">
<LinearLayout
android:id="#+id/layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="0dip">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#FFF"
android:id="#+id/parking_name_info_window"
android:textSize="7pt"
android:singleLine="true"
android:textStyle="bold"
android:ellipsize="end"/>
</LinearLayout>
<RelativeLayout
android:id="#+id/RelativeLayout2"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginTop="2dip">
<RelativeLayout
android:id="#+id/frameLayout1"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#FFF"
android:id="#+id/availability_label_info_window"
android:text="#string/places_str"
android:textStyle="bold"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#FFF"
android:id="#+id/availability_info_window"
android:layout_toRightOf="#+id/availability_label_info_window"
android:layout_marginLeft="5dip" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentRight="true">
<TextView
android:id="#+id/price_label_info_window"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:textStyle="bold"/>
<TextView
android:id="#+id/price_symbol_info_window"
android:layout_toRightOf="#+id/price_label_info_window"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/price_symbol_str"
android:textColor="#FFF"
android:layout_marginLeft="5dip"/>
<TextView
android:id="#+id/price_info_window"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:layout_toRightOf="#+id/price_symbol_info_window"
android:layout_marginLeft="2dip"/>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right"
android:layout_marginBottom="5dip">
</RelativeLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/btn_more_info_disabled"
android:id="#+id/more_info_button"
android:layout_marginLeft="10dip"
android:layout_marginRight="8dip"
android:layout_marginTop="16dip"></ImageView></LinearLayout>
Do you have any idea why its not working?
According to Google, Google Play services API's require 'physical development device', so they are not officially supported on the emulators. So, if you are running on an emulator, it is almost certain you are missing the required services. People report getting it to work in emulators, but I have not tried myself. You can view than answers in this post, if you want to look at installing Google Play on an emulator.
You are getting an error when you try to inflate the MapFragment or SupportMapFragment from your xml. It is usually a good idea to check if the device has Google Play services by calling isGooglePlayServicesAvailable(), and make sure it returns ConnectionResult.SUCCESS before proceeding. This allows you to present an error dialog instead of just crashing. Google has even provided an error dialog for some othercodes, you can have them prompted to upgrade/install via getErrorDialog(), like --
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
switch (resultCode) {
case ConnectionResult.SUCCESS: // proceed
break;
case ConnectionResult.SERVICE_MISSING:
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
case ConnectionResult.SERVICE_DISABLED:
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 1);
dialog.show();
}
Do this before calling setContentView.

Problem with nesting layouts

I have a following situation in my xml:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#drawable/topbar"
>
<TableRow >
<TextView android:minWidth="280sp"
android:id="#+id/header"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#color/path_color"
android:paddingLeft="10px"/>
</TableRow>
</TableLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.solid.explorer.HorizontalPager
android:id="#+id/horizontal_pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</org.solid.explorer.HorizontalPager>
<RelativeLayout
android:id="#+id/contextMenu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone"
>
<org.solid.explorer.ContextOption
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<org.solid.explorer.ContextOption
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<org.solid.explorer.ContextOption
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<org.solid.explorer.ContextOption
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<org.solid.explorer.ContextOption
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
</RelativeLayout>
<LinearLayout
android:id="#+id/drag_view"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone">
<ImageView
android:id="#+id/drag_icon"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<TextView
android:id="#+id/drag_label"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</LinearLayout>
<!-- <ImageView
android:id="#+id/drag_icon1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="gone"
/> -->
</RelativeLayout>
</LinearLayout>
The problem is with the LinearLayout with id drag_view.
In program code, I am using ImageView with id drag_icon1 (it is being dragged by finger). Then everything is fine. But i want to add text to this icon so then I need to drag not the ImageView but the LinearLayout with ImageView and TextView inside, am I right?
But when I switch to the LinearLayout and comment the old ImageView (as in presented xml) the program fails at the setContentView method (second line of onCreate(), so further code has nothing common with this problem). WTF? If drag_icon1 is uncommented and used as dragged image then everything is fine, setContentView works (even with drag_view present).
Here is the stack trace:
E/AndroidRuntime(13517): FATAL EXCEPTION: main
E/AndroidRuntime(13517): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.solid.explorer/org.solid.explorer.Explorer}:java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
E/AndroidRuntime(13517): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
E/AndroidRuntime(13517): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
E/AndroidRuntime(13517): at android.app.ActivityThread.access$1500(ActivityThread.java:132)
E/AndroidRuntime(13517): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
E/AndroidRuntime(13517): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(13517): at android.os.Looper.loop(Looper.java:143)
E/AndroidRuntime(13517): at android.app.ActivityThread.main(ActivityThread.java:4196)
E/AndroidRuntime(13517): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(13517): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(13517): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(13517): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(13517): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(13517): Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
E/AndroidRuntime(13517): at org.solid.explorer.Explorer.onCreate(Explorer.java:126)
E/AndroidRuntime(13517): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
E/AndroidRuntime(13517): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
E/AndroidRuntime(13517): ... 11 more
It suggests that something wrong is with LayoutParams, but with drag_icon1 it works without problems.. I don't have any idea what is wrong.. Thank you for any suggestions
Assuming the layout XML you posted is the complete file, the problems I see are:
You need to have a single root element.
You close a LinearLayout at the bottom of the document that I don't see.
However, if this is true, I'm not sure how you could get it to work by uncommenting the ImageView.

Categories

Resources