I'm trying to use ScrollView and it works fine in Portrait mode but doesn't in Landscape mode. When I start the app, everything's fine but when I turn my phone on the side I have the "ScrollView can host only one direct child" Exception.
Here is my XML code :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="180dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content_show_details_fragment_picture"
android:layout_gravity="center_horizontal"
android:src="#drawable/boiler_room"
android:scaleType="centerCrop"
android:alpha="0.8"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/content_show_details_fragment_title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Titre de l'émission"
android:layout_above="#+id/content_show_details_fragment_subtitle"
android:layout_marginStart="10dp"
android:textColor="#android:color/white"
android:background="#android:color/black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subtitle"
android:id="#+id/content_show_details_fragment_subtitle"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginStart="10dp"
android:layout_marginBottom="10dp"
android:textColor="#android:color/white"
android:background="#android:color/black"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prochaine diffusion"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginTop="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/content_show_details_fragment_date"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginStart="10dp"
android:text="11/11/2014 à 18h00"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Podcasts"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content_show_details_fragment_listView"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
And the Exceptions :
11-25 21:21:57.289 17419-17419/com.readyo.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.readyo.app, PID: 17419
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.readyo.app/com.readyo.app.MainActivity}: java.lang.IllegalStateException: ScrollView can host only one direct child
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2394)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2452)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4035)
at android.app.ActivityThread.access$1000(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5586)
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:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
at android.widget.ScrollView.addView(ScrollView.java:387)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:901)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
at android.app.BackStackRecord.run(BackStackRecord.java:684)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1453)
at android.app.Activity.performStart(Activity.java:5460)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2367)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2452)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4035)
at android.app.ActivityThread.access$1000(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5586)
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:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Related
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.
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.
I am trying to use ViewFlipper, but I am getting this error at the setContentView(R.layout.activity_main); line;
When I back track I get this error when I add the second LinearLayout only.
I looked at examples of of using ViewFlipper and I am not seeing the problem.
here is the XML file:
<LinearLayout
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"
android:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin">
<ViewFlipper
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/viewFlipper">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Date Interval"
android:id="#+id/textView7"
android:layout_weight="1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText6"
android:layout_weight="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText8"
android:layout_weight="1" />
</LinearLayout>
<Button
android:layout_height="33dp"
android:layout_width="wrap_content"
android:text="Get Logs"
android:id="#+id/button6"
android:textSize="12sp"
android:onClick="getLogs" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tableLayout"
android:stretchColumns="*">
</TableLayout>
</ScrollView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="View Time Sheet"
android:id="#+id/button7"
android:layout_gravity="center_horizontal"
android:onClick="viewTimeSheet" />
</LinearLayout>
<linearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<TableLayout
android:id="#+id/amortization"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow android:id="#+id/tableRow">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Project Number/ \n Client Name"
android:id="#+id/textView11"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Project Description"
android:id="#+id/textView19"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 1"
android:id="#+id/textView20"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 2"
android:id="#+id/textView21"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 3"
android:id="#+id/textView22"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 4"
android:id="#+id/textView23"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 5"
android:id="#+id/textView24"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 6"
android:id="#+id/textView25"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 7"
android:id="#+id/textView26"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 8"
android:id="#+id/textView27"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 9"
android:id="#+id/textView28"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 10"
android:id="#+id/textView29"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 11"
android:id="#+id/textView30"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 12"
android:id="#+id/textView31"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 13"
android:id="#+id/textView32"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 14"
android:id="#+id/textView33"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Day 15"
android:id="#+id/textView34"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Total Hrs"
android:id="#+id/textView35"
android:textStyle="bold"/>
</TableRow>
</TableLayout>
</HorizontalScrollView>
</ScrollView>
</linearLayout>
</ViewFlipper>
</LinearLayout>
Here is the activity:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ViewFlipper;
public class MainActivity extends AppCompatActivity {
private ViewFlipper viewFlipper;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void viewTimeSheet(View view){
viewFlipper.showNext();
}
}
Here is the error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.asamater.myapplication/com.example.asamater.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #82: Binary XML file line #82: Error inflating class linearLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #82: Binary XML file line #82: Error inflating class linearLayout
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.example.asamater.myapplication.MainActivity.onCreate(MainActivity.java:17)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #82: Error inflating class linearLayout
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.example.asamater.myapplication.MainActivity.onCreate(MainActivity.java:17)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.linearLayout" on path: DexPathList[[zip file "/data/app/com.example.asamater.myapplication-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.asamater.myapplication-1/lib/x86, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:583)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:677)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.example.asamater.myapplication.MainActivity.onCreate(MainActivity.java:17)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Suppressed: java.lang.ClassNotFoundException: android.view.linearLayout
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 29 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
Here:
<linearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
</linearLayout>
should be:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
</LinearLayout>
(Upper Cap)
Note that XML is case-sensitive.
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.
So I recently updated this app to API 21, and consequentially I changed all my ActionBar to Toolbar.
I include the toolbar into the fragment layout using tag, and I set it up in onResume() method. All is working fine when I launch the app, and when I put it in background and immediately restore it (or in a couple of minutes), but if I let it in background for a little, and maybe use some other app, when I restore it, I've a crash. The crash happen in the second line of the setupToolbar() method, surely because the toolbar object is null. My problem is to understand why this object is null, because when I restore the app, the execution flow have to execute onCreateView() first, and then onResume (and so setupToolbar). So the toolbar have to be inflated in the layout.
This is my toolbar layout that's included in fragment_home:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_gravity="center">
<ImageView
android:layout_width="40dp"
android:layout_height="match_parent"
android:src="#drawable/actionbar_menu"
android:scaleType="center"
android:id="#+id/ivActionbarOpenDrawer"
android:layout_alignParentLeft="true"
android:layout_marginLeft="12dp"
android:padding="5dp"
android:clickable="true"/>
<ImageView
android:layout_width="40dp"
android:layout_height="match_parent"
android:src="#drawable/back_icon"
android:visibility="gone"
android:scaleType="center"
android:id="#+id/ivActionbarBack"
android:layout_alignParentLeft="true"
android:layout_marginLeft="12dp"
android:padding="5dp"
android:clickable="true"/>
<RelativeLayout
android:layout_width="18dp"
android:layout_height="18dp"
android:id="#+id/rlActionbarNotificationNumContainer"
android:background="#drawable/circle_shape_notifies_white"
android:layout_alignParentLeft="true"
android:layout_marginLeft="35dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:layout_gravity="center"
android:visibility="invisible">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tvActionbarNotificationIndicator"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginTop="-2dp"
android:textColor="#color/app_red"
android:textSize="14sp"/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:id="#+id/tv_actionBarText"
android:text="home"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="18sp"
android:layout_centerInParent="true"
android:visibility="visible"/>
<ImageView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:src="#drawable/search_icon"
android:scaleType="fitEnd"
android:layout_margin="10dp"
android:layout_marginRight="20dp"
android:padding="5dp"
android:layout_alignParentRight="true"
android:id="#+id/ivSearchIconActionbar"/>
<ImageView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/ivActionbarNewMsgMessages"
android:layout_centerVertical="true"
android:background="#drawable/new_message_icon_messages"
android:layout_margin="10dp"
android:visibility="gone"
android:padding="8dp"
android:layout_alignParentRight="true"/>
<ImageView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/ivActionbarSettingsProfile"
android:layout_centerVertical="true"
android:background="#drawable/icon_settings_profile"
android:layout_margin="10dp"
android:visibility="gone"
android:padding="12dp"
android:layout_alignParentRight="true"/>
</RelativeLayout>
and this is setupToolbar method:
private void setupToolbar() {
Toolbar toolbar = (Toolbar) getActivity().findViewById(R.id.toolbarHome);
ImageView ivSearch = (ImageView) toolbar.findViewById(R.id.ivSearchIconActionbar);
ImageView ivMenu = (ImageView) toolbar.findViewById(R.id.ivActionbarOpenDrawer);
ivSearch.setOnClickListener(onSearchClick);
ivMenu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
((MainActivity) getActivity()).openOrCloseDrawer();
}
});
}
EDIT: Here the stacktrace
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.twentyLines.app/com.twentyLines.app.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$600(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5454)
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:1029)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.twentyLines.app.controller.HomeController.setupToolbar(HomeController.java:231)
at com.twentyLines.app.controller.HomeController.onActivityCreated(HomeController.java:123)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1794)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:967)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1108)
at
android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1917)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:544)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1225)
at android.app.Activity.performStart(Activity.java:5076)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$600(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5454)
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:1029)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
at dalvik.system.NativeStart.main(Native Method)
Not able to figure it out, any help will be really valued!
Thanks in advance