-2

I have an android application which has more than 20 layouts. In recent days if I make any changes in layout (generally id changing, creating new component or layout) crashes my app or changes some layouts by itself. I have a menu and when I click menu icon it shows my custom actionbar layout instead of custom menu layout. Most of time app crashes.

I have tired clean and rebuild project but it doesnt work. I made some search but there is nothing about it. Please help me.

  • 1
    Check your `MainActivity`, more specifically, a the part where you are trying to set an `OnClickListener` on a relative layout. Maybe you have changed an id or something, but the target `RelativeLayout` is `null`. Posting your activity layout can also be helpful, if you can't find the problem yourself. – Danail Alexiev Jun 15 '16 at 11:49
  • 1
    can you post some code ? – PedroAGSantos Jun 15 '16 at 11:52
  • when I remove page and run it works again there is no problem about RelativeLayout. it crashes everytime when I create new xml page. I think it is about R.java id problem. – Cenk Cavga Jun 15 '16 at 11:53
  • it is not R.id problem. pls post your xml – Kailash Dabhi Jun 15 '16 at 11:54
  • You forgot the `findViewById()` call – EpicPandaForce Jun 15 '16 at 11:59
  • Dear my friends There is not a problem about java code. The problem is when I create a new layout page in layout folder without any usage it gives crash. The problem looks like about compiling not coding. – Cenk Cavga Jun 15 '16 at 12:10

4 Answers4

0

Welcome on stackoverflow.

As per below line of your error log you need to bind your RelativeLayout which you are using for click listener.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.RelativeLayout.setOnClickListener(android.view.View$OnClickListener)' on a null object reference

Please check all layout is properly bind.See below example:

RelativeLayout youRelativeLayout=findViewById(R.id.yourRelativeLayoutId);

Then set clickListener.

pRaNaY
  • 24,642
  • 24
  • 96
  • 146
  • There is no problem about my bindings in Java. The problem is I cant add even an empty layout to my layout folder without any usage. I think it is a compiling error – Cenk Cavga Jun 15 '16 at 12:08
  • If you post some code which you are trying, which help us more about problem. – pRaNaY Jun 15 '16 at 12:18
0

Once check, are you giving old id's to new Views in new Layout. and check all id's you have given in layout files.

Narender Reddy
  • 463
  • 6
  • 18
0

Don't use your Relative Layout as a .setOnClickListener, Use the widgets within the Relative Layout to use methods such as .setOnClickListener.

ESPA_NETwork
  • 165
  • 2
  • 14
0

First check it your xml you using Relative layout in this using same as:

android:layout_below="@id/LoginTitle"

add + symbol after @id/LoginTitle

When there is no problem you see after check in your java file: is null because you never initialize it with: so initialize same as below initialize.

Button mAddTaskButton = (Button) findViewById(R.id.addTaskButton);
Eugene S
  • 6,709
  • 8
  • 57
  • 91
Praveen Singh
  • 116
  • 1
  • 10