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

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

Related

Snackbar Error in activity => android.view.InflateException: <merge /> can be used only with a valid ViewGroup root and attachToRoot=true

After updating the android studio to version 3.1.2 & gradle to version 4.4, I've faced weird problem to show snackbar in an activtiy.
here is the code:
#BindView(R.id.layout_coordinator)
CoordinatorLayout coordinatorLayout;
Snackbar.make(coordinatorLayout,"hello", Snackbar.LENGTH_LONG).show();
my XMl layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activities.LoginActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="70dp"
android:paddingRight="70dp">
<EditText
android:id="#+id/edtMobileNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/txt_RegisterTitle"
android:layout_marginTop="19dp"
android:gravity="center"
android:hint="#string/enterYourMobilePhone"
android:inputType="number"
android:maxLength="11"
android:maxLines="1" />
<Button
android:id="#+id/btn_Confirm"
android:layout_width="130dp"
android:layout_height="40dp"
android:layout_below="#+id/edtMobileNumber"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:background="#drawable/button_background_green"
android:text="#string/confirm"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white" />
</RelativeLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
And this is the errro I've got:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.company.myproject/com.company.myproject.Activities.LoginActivity}: android.view.InflateException: <merge /> can be used only with a valid ViewGroup root and attachToRoot=true
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2702)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: android.view.InflateException: <merge /> can be used only with a valid ViewGroup root and attachToRoot=true
at android.view.LayoutInflater.inflate(LayoutInflater.java:476)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.support.design.widget.Snackbar.make(Snackbar.java:143)
at com.company.myproject.Activities.LoginActivity.onCreate(LoginActivity.java:98)
as you can see, the error is about inflating layout but can't understand the reason:
Caused by: android.view.InflateException: can be used only with a valid ViewGroup root and attachToRoot=true
It must be mentioned that I've used every solution that are suggested :
my support design version is : implementation com.android.support:design:27.1.1'
the activtiy is extend from AppCompatActivity
The AppTheme is Theme.AppCompat.Light.NoActionBar
I've used getWindow().getDecorView().findViewById(R.id.layout_coordinator), but nothing is solved
be glad someone could help me.
Finally, I've found the solution:
There is a MERGE tag in the snackbar layout that cause exception while inflating layout. By commenting the related row, the problem is solved.

Add a Button to GoogleMap in Android

Hello guys This my Xml code
I use Relative Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
<Button
android:id="#+id/add_restaurant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="new mark" />
<Button
android:id="#+id/remove_restaurant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#id/add_restaurant"
android:text="clear mark" />
/>
<Button
android:id="#+id/check_map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#id/remove_restaurant"
android:text="just check" />
/>
</RelativeLayout>
It can show correctly just like the following image
Image
But when I opened the APP with my mobile, it just crashed
How can I solve it?
Error Message from Android Studio
10-15 20:43:30.100 20922-20922/com.ncku.addmarker E/AndroidRuntime: FATAL
EXCEPTION: main
Process:
com.ncku.addmarker, PID: 20922
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.ncku.addmarker/com.ncku.addmarker.MapsActivity}:
java.lang.NullPointerException: Attempt to invoke virtual method 'void
com.google.android.gms.maps.SupportMapFragment.getMapAsync(com.google.android.gms.maps.OnMapReadyCallback)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2509)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2569)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5885)
at java.lang.reflect.Method.invoke(Native Method)
atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.SupportMapFragment.getMapAsync(com.google.android.gms.maps.OnMapReadyCallback)' on a null object reference
at com.ncku.addmarker.MapsActivity.onCreate(MapsActivity.java:24)
at android.app.Activity.performCreate(Activity.java:6262)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2462)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2569) 
at android.app.ActivityThread.access$900(ActivityThread.java:150) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:168) 
at android.app.ActivityThread.main(ActivityThread.java:5885) 
at java.lang.reflect.Method.invoke(Native Method) 
atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:797) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) 
For UI, you need to change your code...
If you want to add button on map fragment, then you need to add frame layout. As frame layout give an option to add the component on to the other component as a layer.
For crash, please provide crash logs.
Cheers!!!
I think this error showing because you have to not Generate a API key on google console. If you have try to load a map then you have must to Generate a API key.Try to this link and do step by step..
https://developers.google.com/maps/documentation/android-api/

Unfortunately, App has stopped on physical device when making changes to .xml in layout-land file in Android [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
In chapter 3 of Big Nerd Ranch guide, they explain how to differently layout the default and landscape views. But when I create an Android Resource Directory with Landscape orientation and then copy the same .xml from the default layout into the /layout-land and make changes into the latter, the app crashes on my physical device when I rotate to landscape mode.
If I don't change anything in the copied .xml inside the /layout-land file, it runs absolutely fine when rotated.
activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
>
<TextView
android:id="#+id/question_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/true_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/true_button"/>
<Button
android:id="#+id/false_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/false_button"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/prev_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/prev_button"/>
<Button
android:id="#+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/next_button"/>
</LinearLayout>
</LinearLayout>
/layout-land/activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
>
<TextView
android:id="#+id/question_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/true_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/true_button"/>
<Button
android:id="#+id/false_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/false_button"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/prev_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/prev_button"/>
</LinearLayout>
</LinearLayout>
Logcat
FATAL EXCEPTION: main
Process: com.bignerdranch.android.geoquiz, PID: 5727
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bignerdranch.android.geoquiz/com.bignerdranch.android.geoquiz.QuizActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2695)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4378)
at android.app.ActivityThread.access$1000(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1436)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5910)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.bignerdranch.android.geoquiz.QuizActivity.onCreate(QuizActivity.java:81)
at android.app.Activity.performCreate(Activity.java:6178)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2648)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769) 
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4378) 
at android.app.ActivityThread.access$1000(ActivityThread.java:177) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1436) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5910) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372)
Cannot figure out what is the problem. Please help
You can have different layout files that appear different, but if you are using findViewById on views that do not exist (such as the next button), then you'll get a NullPointerException when you go to call any methods on that view (such as assign it's click listener, in the case of your error).
The simple solution is to keep all the views in both layouts with the same ids, but just rearrange them according to the orientation.

IllegalArgumentException: No view found for id - on app restart

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>

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