Android how to open a popup window in an onclick function - android

In android I am trying to open a popup window to get some user input but the code fails in Activity.java on
if (activity == null && children == null && fragments == null && loaders == null
&& mVoiceInteractor == null) {
return null;
}
Here are the xml files of the layout with the button to open the popup window and the xml of the popup window
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="15dip"
android:layout_marginTop="10dip"
android:text="Manually Enter Latitude and Longitude"
android:background="#778899"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_marginTop="10dp"
android:text="Latitude"
android:background="#778899"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:paddingLeft="30dip"
android:paddingRight="30dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:textSize="14sp"
android:text="Decimal\nDegrees"
android:id="#+id/button_lat_dec_deg"
android:onClick="enter_lat_dec_deg"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:paddingLeft="10dip"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_gravity="center"
android:text="OR"
android:background="#778899"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="5dp"
android:textSize="14sp"
android:text="Degrees,\nMinutes and Seconds"
android:id="#+id/button_lat_deg_min_sec"
android:onClick="enter_lat_d_m_s"
android:layout_gravity="right"
android:singleLine="false" />
</LinearLayout>
<View android:id="#+id/separator"
android:background="#000000"
android:layout_width = "fill_parent"
android:layout_height="1dp"
android:layout_marginTop="30dp"
android:layout_centerVertical ="true"
android:layout_alignParentTop="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:paddingLeft="25dip"
android:paddingRight="25dip"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_marginTop="10dp"
android:text="Longitude"
android:background="#778899"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:paddingLeft="30dip"
android:paddingRight="30dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:textSize="14sp"
android:text="Decimal\nDegrees"
android:id="#+id/button_lon_dec_deg"
android:onClick="enter_lon_dec_deg"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:paddingLeft="10dip"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_gravity="center"
android:text="OR"
android:background="#778899"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="5dp"
android:textSize="14sp"
android:text="Degrees\nMinutes and Seconds"
android:id="#+id/button_lon_deg_min_sec"
android:onClick="enter_lon_d_m_s"
android:layout_gravity="right"
android:singleLine="false" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/manually_entry" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Please enter the decimal Latitude"
android:singleLine="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Negative is South"
android:singleLine="true"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:inputType="numberDecimal|numberSigned"
android:id="#+id/enter_decimal_number" />
</LinearLayout>
and the code for the onclick function is
public void enter_lat_dec_deg(View v) {
layout3 = inflater.inflate(R.layout.manually_enter_numbers, (ViewGroup) findViewById(R.id.manually_entry));
enter_manual_dec_deg = new PopupWindow(layout3 , 700,900,true); // width, height
layout3.post(new Runnable() {
public void run() {
enter_manual_dec_deg.showAtLocation(layout3, Gravity.CENTER, 0, 200);
}
});
input = (EditText) findViewById(R.id.enter_decimal_number);
decimal_input = Float.valueOf(input.getText().toString());
Toast.makeText(GPSTest.this, "this is the decimal input !!!" + decimal_input,
Toast.LENGTH_LONG).show();
}
I have another popup window in the same app that works fine but the same code does not work here.
I am quite new to android programming have probably made a quite obvious mistake but I have done lots of googling and found nothing to fix the problem so any advice would be eagerly anticipated.
Please ask if you would like me to post more code.
The android studio event log has :
14:03:52 Session 'GPSTest': Launched on gigabyte-guru__gx-487d40a0
14:04:53 null
java.nio.BufferOverflowException
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:206)
at com.android.ddmlib.JdwpPacket.movePacket(JdwpPacket.java:235)
at com.android.ddmlib.Debugger.sendAndConsume(Debugger.java:347)
at com.android.ddmlib.Client.forwardPacketToDebugger(Client.java:709)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:346)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:265)
14:04:53 null
java.nio.BufferOverflowException
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:206)
at com.android.ddmlib.JdwpPacket.movePacket(JdwpPacket.java:235)
at com.android.ddmlib.Debugger.sendAndConsume(Debugger.java:347)
at com.android.ddmlib.Client.forwardPacketToDebugger(Client.java:709)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:346)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:265)
14:05:26 Executing tasks: [:app:assembleDebug]
14:05:26 Gradle build finished in 679ms
14:48:36 null
java.nio.BufferOverflowException
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:206)
at com.android.ddmlib.JdwpPacket.movePacket(JdwpPacket.java:235)
at com.android.ddmlib.Debugger.sendAndConsume(Debugger.java:347)
at com.android.ddmlib.Client.forwardPacketToDebugger(Client.java:709)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:346)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:265)
and here is the logcat :
03-03 14:45:49.629 18174-18174/? D/AndroidRuntime: Shutting down VM
03-03 14:45:49.629 18174-18174/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4165cd58)
03-03 14:45:49.649 18174-18180/? D/dalvikvm: Debugger has detached; object registry had 3717 entries
03-03 14:45:49.649 18174-18174/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.david.gpstest, PID: 18174
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3823)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18439)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5095)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3818)
at android.view.View.performClick(View.java:4438) 
at android.view.View$PerformClick.run(View.java:18439) 
at android.os.Handler.handleCallback(Handler.java:733) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5095) 
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:786) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NullPointerException
at com.example.david.gpstest.GPSTest.enter_lat_dec_deg(GPSTest.java:156)
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at android.view.View$1.onClick(View.java:3818) 
at android.view.View.performClick(View.java:4438) 
at android.view.View$PerformClick.run(View.java:18439) 
at android.os.Handler.handleCallback(Handler.java:733) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5095) 
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:786) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) 
at dalvik.system.NativeStart.main(Native Method) 
03-03 14:45:52.259 18174-18174/com.example.david.gpstest I/Process: Sending signal. PID: 18174 SIG: 9
The code fails at the line :
layout3 = inflater.inflate(R.layout.manually_enter_numbers, (ViewGroup) findViewById(R.id.manually_entry));

David, Hello its yourself here. This is a design fault. Please redesign your app to use activities instead of popups. Have a nice day.

Related

Android layout inflate exception in fragments

my app is suffering from crash whenever i press back key. basically i have 4 fragments but app crashes only when it comes back on my first fragment.
FATAL EXCEPTION: main
Process: , PID: 5835
android.view.InflateException: Binary XML file line #16: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:770)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at NewBookingFragment.onCreateView(NewBookingFragment.java:174)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.popFromBackStack(BackStackRecord.java:979)
at android.support.v4.app.FragmentManagerImpl.popBackStackState(FragmentManager.java:1670)
at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:586)
at android.support.v4.app.FragmentActivity.onBackPressed(FragmentActivity.java:188)
at HomeActivity.onBackPressed(HomeActivity.java:161)
at android.app.Activity.onKeyUp(Activity.java:2576)
at android.view.KeyEvent.dispatch(KeyEvent.java:3171)
at android.app.Activity.dispatchKeyEvent(Activity.java:2831)
at android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:534)
at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:50)
at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:241)
at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:50)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2429)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4580)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4535)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4070)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4123)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4089)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4199)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4097)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4256)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4070)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4123)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4089)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4097)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4070)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4123)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4089)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4232)
at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4419)
at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2480)
at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:2074)
at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:2065)
at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2457)
at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:143)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
Code-
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);//line 161
} else {
super.onBackPressed();
}
}
XML Code which is causing issue:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.app.myapp.HomeActivity"
>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
class="com.app.myapp.TouchableSupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<RelativeLayout
android:id="#+id/rlDriverProgress"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:background="#drawable/oval_progress"
android:padding="5dp"
>
<ProgressBar
android:id="#+id/getDriversProgress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlTimeRequired"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:background="#drawable/oval_progress"
android:padding="5dp"
android:gravity="center|center_vertical|center_horizontal"
>
<TextView
android:layout_width="25dp"
android:layout_height="wrap_content"
android:text="10"
android:textStyle="bold"
android:textSize="17sp"
android:gravity="center|center_horizontal|center_vertical"
android:textColor="#color/colorWhite"
android:id="#+id/tvNoOfMins"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MIN"
android:textStyle="bold"
android:textSize="15sp"
android:textColor="#color/colorWhite"
android:id="#+id/tvMinsHeading"
android:layout_below="#+id/tvNoOfMins"
/>
</RelativeLayout>
<LinearLayout
android:id="#+id/llSearchBar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="center_horizontal|top"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="100dp"
android:background="#drawable/bg_search_bar"
android:orientation="horizontal">
<ImageView
android:id="#+id/icSelectPickup"
android:layout_width="45dp"
android:layout_height="23dp"
android:layout_gravity="center"
android:src="#drawable/icon_search"
/>
<EditText
android:id="#+id/tvPickupAddress"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_weight="1"
android:background="#null"
android:editable="false"
android:elegantTextHeight="false"
android:enabled="true"
android:focusable="true"
android:focusableInTouchMode="false"
android:text="Select Pickup Address"
android:textAlignment="gravity"
android:gravity="center_vertical|center_horizontal"
android:textSize="16sp"
android:textStyle="normal" />
</LinearLayout>
<!--android:textColor="#color/whiteTranparent" -->
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="faisal"
android:id="#+id/dummyCenterTV"
/>
<ImageView
android:id="#+id/pickupLocationPin"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/dummyCenterTV"
android:src="#drawable/carpin" />
<LinearLayout
android:id="#+id/layoutBookButtons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:orientation="vertical"
android:layout_alignParentBottom="true"
>
<Button
android:id="#+id/btnPickLater"
android:layout_width="100dp"
android:layout_height="30dp"
android:text="Book Later"
android:layout_gravity="right|bottom"
android:layout_marginBottom="3dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:textSize="11dp"
android:background="#drawable/rc_primary_button"
android:textColor="#color/colorWhite"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/label_pick_now"
android:textAllCaps="false"
android:id="#+id/btnPickNow"
android:background="#color/colorAccent"
android:textColor="#color/colorWhite"
android:textSize="18dp"
android:textStyle="bold"
android:focusable="true"
android:clickable="true"
/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
i think map fragment section is the part crashing app. please have a look
Your error occurs here:
com.app.minicabscouk.HomeActivity.onBackPressed(HomeActivity.java:161)
That's line 161 of your HomeActivity. You'll need to post the code from that class if you still can't figure it out yourself.
Hey, turns out I made a mistake! Disregard my above answer, sorry.
Check out the first line here:
FATAL EXCEPTION: main Process: , PID: 5835 android.view.InflateException: Binary XML file line #16: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:770)
That's your actual problem. Whichever fragment you're trying to create, there's a problem with the XML at line 16.

Android OutOfMemoryError in SetContentView line

When i try to open my chat class , sometimes it runs properly , sometimes it gives OutOfMemoryError at setContentView line.I can't understand what is the cause of problem?
Here is my xml code :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbarmesajlasma"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/ColorPrimary"
android:elevation="1dp">
<RelativeLayout
android:id="#+id/layoutmesajlasma"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000">
<ImageButton
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_centerVertical="true"
android:background="#00000000"
android:longClickable="false"
android:src="#mipmap/geribas" />
<ImageButton
android:id="#+id/imageButton"
android:layout_width="43dp"
android:layout_height="43dp"
android:layout_marginLeft="35dp"
android:background="#00000000"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/textView2"
android:layout_width="135dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="85dp"
android:text="Abdurrahman"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_centerVertical="true"
android:textColor="#ffffff"
android:textIsSelectable="false"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:layout_below="#+id/toolbarmesajlasma"
android:background="#mipmap/maybehi">
<ListView
android:id="#+id/listView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#00000000"
android:dividerHeight="4dp"
android:layout_alignParentTop="true"
android:layout_above="#+id/linearLayout" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#mipmap/bisiler_yaz_altplan"
android:id="#+id/linearLayout">
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bisiler_yaz"
android:hint="Bir mesaj yaz..."
android:imeOptions="actionNone"
android:textSize="14dp"
android:textStyle="bold"
android:layout_marginRight="5dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="5dp"
android:capitalize="sentences"
android:allowUndo="true"
android:width="295dp"
android:inputType="textCapSentences" />
<ImageButton
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="false"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="bottom"
android:background="#00000000"
android:src="#mipmap/gonder"
android:text="Gonder"
android:layout_marginBottom="10dp" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ivYatay"
android:src="#drawable/horizontalrope"
android:layout_marginTop="56dp"
android:layout_marginLeft="118dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ivCapraz"
android:src="#drawable/diagonalrope"
android:layout_marginTop="50dp"
android:layout_marginLeft="92dp"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="invisible"
android:id="#+id/imageView6"
android:background="#mipmap/gri"
android:layout_marginTop="45dp" />
</FrameLayout>
Here is the error :
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:683)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:513)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:889)
at android.content.res.Resources.loadDrawable(Resources.java:3436)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3708)
at android.widget.ImageView.<init>(ImageView.java:127)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:963)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1022)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at droxoft.armin.com.shappy.Mesajlasma.onCreate(Mesajlasma.java:223)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
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:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Your OOM error is related to the Images you are loading as I am seeing in your log trace.
See this for loading large Bitmaps more efficiently:
A 400 KB image file can easily take up 5-10 MB of RAM.
For requesting to incraese heap size dynamically, Use android:largeHeap="true"
in the manifest.xml.
or/and just use the proper function to decode...
I would check the size of all your images referred to in your ImageViews. If they are large, maybe encode them as different image types to reduce the image size. The Android system is periodically running out of memory and crashing your application currently. It makes sense that you are getting this only sometimes as it depends on how much memory is currently being used for other applications etc... . If you reduce the size of your images significantly you should be able to resolve this.
Increase the gradle.properties in the root of your project :
org.gradle.jvmargs=-XX:MaxHeapSize\=512m -Xmx512m
the default jvmargs is 256
you can request to use more by using.
android:largeHeap="true"
in the manifest.xml.

I'm trying to scroll to a particular portion of my TableLayout using scrollTo()

I have a TableLayout within ScrollView:
ScrollView helpSV;
TableLayout myTL;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
helpSV = (ScrollView) findViewById(R.id.helpScrollView);
myTL = (TableLayout) findViewById(R.id.myTableLayout);
}
Also, on clicking a button, a function is made to run:
<Button
android:id="#+id/regButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button"
android:gravity="left|center_vertical"
android:onClick="register"
android:paddingLeft="20dp"
android:text="Registration"
android:textColor="#fff" />
register() function is as follows:
public void register(View view) {
int index = 5;
final View child = myTL.getChildAt(index);
new Handler().post(new Runnable() {
#Override
public void run() {
helpSV.smoothScrollTo(0, child.getBottom());
}
});
}
For some reason, my app force closes on clicking the button. I've been at this for hours, referred to similar questions but nothing helped so far..
Help? Thanks in advance...
Error log:
Caused by: java.lang.NullPointerException
at com.android.aashima.my_app.HelpActivity.register(HelpActivity.java:65)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at android.view.View$1.onClick(View.java:2139)
            at android.view.View.performClick(View.java:2485)
            at android.view.View$PerformClick.run(View.java:9080)
            at android.os.Handler.handleCallback(Handler.java:587)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:130)
            at android.app.ActivityThread.main(ActivityThread.java:3687)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
            at dalvik.system.NativeStart.main(Native Method)
XML:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/redblack"
android:padding="5dp"
android:id="#+id/helpScrollView">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/myTableLayout">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/row1">
<Button
android:id="#+id/regButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button"
android:gravity="left|center_vertical"
android:onClick="register"
android:paddingLeft="20dp"
android:text="REGISTRATION"
android:textColor="#fff" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="20dp"
android:id="#+id/row6">
<ImageView
android:id="#+id/regImg"
android:src="#drawable/scr5"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="50dp"
android:layout_marginBottom="50dp"
android:id="#+id/row7">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="#string/back"
android:id="#+id/back1"
android:background="#drawable/roundedbutton"
android:padding="10dp"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp"
android:id="#+id/row8">
<ImageView
android:id="#+id/locImg"
android:src="#drawable/scr72"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp"
android:id="#+id/row9">
<ImageView
android:id="#+id/locImg2"
android:src="#drawable/scr9"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp"
android:id="#+id/row10">
<ImageView
android:id="#+id/locImg3"
android:src="#drawable/scr10"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp"
android:id="#+id/row11">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="#string/back"/>
</TableRow>
</TableLayout>
If anybody gets this problem, its probably cos you have made a re-declaration of some variable accidentally.
That's what caused the error in my program..silly me
I'd say you're crashing because View child is null. getChildAt() only gets the visible children, so you shouyld use getChildCount() and getFirstVisiblePosition() to check what is the index of the first visible child and the index of the last visible child by adding count and first visible position.
Also, you could scroll using smoothScrollToPosition() to get directly to the child of interest.

Android - Throwing fatal exception where it wasn't before

Explanation at the end of the code
Java:
void GetNextQuestion()
{
QuestNum++;
/// ERROR ON VERY NEXT LINE
ProgressBar pbar = (ProgressBar)this.findViewById(R.id.progressBar2);
TextView tvSection = (TextView)this.findViewById(R.id.section);
TextView tvSubsection = (TextView)this.findViewById(R.id.subsection);
TextView tvQuest = (TextView)this.findViewById(R.id.quest);
if(QuestNum > 0 && QuestNum < 180)
{
tvSection.setText(R.string.s1);
tvSubsection.setText(R.string.ss1);
spin.setSecondaryProgress((int)((QuestNum/180) * 1000));
}
if(QuestNum > 179 && QuestNum < 285)
{
tvSection.setText(R.string.s2);
tvSubsection.setText(R.string.ss2);
}
}
XML:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/lib/com.google.ads">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:id="#+id/icon"
android:layout_width="57dp"
android:layout_height="54dp"
android:src="#drawable/devil" />
<TextView
android:id="#+id/section"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/icon"
android:text="#string/nunca"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="invisible" />
<TextView
android:id="#+id/subsection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/section"
android:layout_alignParentRight="true"
android:layout_below="#+id/icon"
android:text="#string/nunca"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:id="#+id/help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/helpico" />
<ImageView
android:id="#+id/exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/subsection"
android:layout_alignParentRight="true"
android:src="#drawable/exitico" />
<TextView
android:id="#+id/haveyou"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/subsection"
android:layout_marginTop="18dp"
android:text="#string/nunca"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/quest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/load"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/butyes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_above="#+id/progressBar2"
android:layout_marginBottom="30dp"
android:text="Yes" />
<Button
android:id="#+id/butno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_above="#+id/progressBar2"
android:layout_marginBottom="30dp"
android:text="No" />
<ProgressBar
android:id="#+id/progressBar2"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:max="1000"
android:progress="0"/>
</RelativeLayout>
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:adSize="BANNER"
app:adUnitId="a14ffb06b21e68e"
app:loadAdOnCreate="true" >
</com.google.ads.AdView>
</LinearLayout>
Error:
E/AndroidRuntime(20649): FATAL EXCEPTION: main
E/AndroidRuntime(20649): java.lang.ClassCastException: android.widget.Button
at com.ndai.ptest.a1000test.GetNextQuestion(a1000test.java:146)
at com.ndai.ptest.a1000test$QuestAnsTask.onPostExecute(a1000test.java:3319)
at com.ndai.ptest.a1000test$QuestAnsTask.onPostExecute(a1000test.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:417)
at android.os.AsyncTask.access$300(AsyncTask.java:127)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
here is what i don't understand...it is giving me a casting error...i am casting a progressbar tp a progressbar...am i just missing a typo or something...i just need an extra set of eyes on this one
EDIT:
I did however not receive this error until after i rearranged stuff on the xml
I FIXED IT
I was reading how other people have been having the same issues when not using the GUI to change the layout...so i followed these steps
Fix the project (right click project, got android tools then the only option that says fix)
Delete R.java
Fix The Project again
What was happening is that eclipse (Or what ever you use) didn't want to update R file with the right data, meaning that the id of your progress bar or what ever it was casting was being mixed up with one of the buttons, nice little bug for ya.

Why does adding a checkbox to an XML layout cause a java.lang.ClassCastException?

I am modifying someone else's code, and just trying to add a fourth checkbox to the following dialog:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<CheckBox
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:text="#string/vinai_full"
android:checked="true"
android:id="#+id/cb_vinai"
android:layout_height="wrap_content"/>
<CheckBox
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:text="#string/suttan_full"
android:checked="true"
android:id="#+id/cb_suttan"
android:layout_height="wrap_content"/>
<CheckBox
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:text="#string/abhidum_full"
android:checked="true"
android:id="#+id/cb_abhidham"
android:layout_height="wrap_content"/>
<Button
android:text="#string/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/okcatebtn"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:layout_gravity="center"
/>
</LinearLayout>
The fourth checkbox is:
<CheckBox
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:text="#string/etc_full"
android:checked="true"
android:id="#+id/cb_etc"
android:layout_height="wrap_content"/>
When I add it in, the apk compiles fine, but the program crashes on startup:
E/AndroidRuntime( 1470): FATAL EXCEPTION: main
E/AndroidRuntime( 1470): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.yuttadhammo.tipitaka/org.yuttadhammo.tipitaka.SelectBookActivity}: java.lang.ClassCastException: android.widget.Gallery
E/AndroidRuntime( 1470): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
E/AndroidRuntime( 1470): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
E/AndroidRuntime( 1470): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime( 1470): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
E/AndroidRuntime( 1470): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1470): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1470): at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 1470): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1470): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 1470): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 1470): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 1470): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1470): Caused by: java.lang.ClassCastException: android.widget.Gallery
E/AndroidRuntime( 1470): at org.yuttadhammo.tipitaka.SelectBookActivity.onCreate(SelectBookActivity.java:586)
E/AndroidRuntime( 1470): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 1470): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
E/AndroidRuntime( 1470): ... 11 more
This is even though the dialog is not loaded at startup. If I replace the third checkbox with the fourth one, there is no crash, so it seems like for some reason it is simply not accepting a fourth element. Why would that be?
EDIT: Here's the code leading up to the error, but I don't understand how it is related, since it refers to an element in a differing layout file:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
main = View.inflate(this, R.layout.main, null);
setContentView(main);
searchHistoryDBAdapter = new SearchHistoryDBAdapter(SelectBookActivity.this);
searchResultsDBAdapter = new SearchResultsDBAdapter(SelectBookActivity.this);
bookmarkDBAdapter = new BookmarkDBAdapter(SelectBookActivity.this);
Context context = getApplicationContext();
prefs = PreferenceManager.getDefaultSharedPreferences(context);
MainTipitakaDBAdapter mainTipitakaDBAdapter = new MainTipitakaDBAdapter(this);
try {
mainTipitakaDBAdapter.open();
if(mainTipitakaDBAdapter.isOpened()) {
mainTipitakaDBAdapter.close();
} else {
startDownloader();
}
} catch (SQLiteException e) {
Log.e ("Tipitaka","error:", e);
startDownloader();
}
Resources res = getResources();
final String [] cnames = res.getStringArray(R.array.category);
textInfo = (TextView) findViewById(R.id.text_info);
and here's main.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="horizontal|vertical">
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:padding="3dp"
android:id="#+id/about_header">
<TextView
android:id="#+id/about_text_1"
android:layout_marginLeft="1dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/about_logo"
android:layout_centerVertical="true"
android:text="Android Tipitaka"
android:textSize="24sp"
android:textColor="#android:color/primary_text_dark_nodisable"/>
</RelativeLayout>
<View
android:background="#drawable/black_white_gradient"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:layout_height="2dp"/>
<Gallery
android:layout_width="match_parent"
android:id="#+id/gallery_cate"
android:spacing="6dp"
android:gravity="center_vertical"
android:layout_height="60dp"/>
<TextView
android:id="#+id/book_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/th_book_label"
android:textSize="17sp"
/>
<Gallery
android:id="#+id/gallery_ncate"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center_vertical"
android:spacing="25dp"
/>
<TextView
android:id="#+id/text_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:lines="2"
android:layout_marginBottom="5dp"
android:layout_gravity="center_vertical|center_horizontal|center"
android:gravity="center_vertical|center_horizontal"
android:text=""
android:textSize="17sp"
/>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/main_buttons"
android:layout_gravity="center_horizontal">
<Button
android:id="#+id/read_btn"
android:layout_width="85dp"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:layout_gravity="center_vertical|center_horizontal|center"
android:text="#string/th_read"
android:textStyle="bold"
android:textSize="16dp"
android:layout_marginRight="40dp"
/>
<Button
android:id="#+id/search_btn"
android:text="#string/th_search"
android:layout_toRightOf="#id/read_btn"
android:layout_width="85dp"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:layout_gravity="center_vertical|center_horizontal|center"
android:textStyle="bold"
android:textSize="16dp"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
if text_info is in diffrent layout then use this
textInfo = (TextView)your_layout.findViewById(R.id.text_info);
instead of
textInfo = (TextView)findViewById(R.id.text_info);
Be sure when you use
myContext.findViewById(R.id.cb_etc);
You assign it to a CheckBox object.
CheckBox mCheckBox = (CheckBox) myContext.findViewById(R.id.cb_etc);
NOTE: If you are using another layout, then you need to cast findViewBy id with that layout or the Context of the layout.
I had also same problem. but i add an attribute in Linearlayout for id
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
and it solved.
Actually, the answer turned out to be running ant clean - the problem was there were cached files in the gen directory that were causing confusion for the device.

Categories

Resources