Java Illegal Argument Exception android - android

I am having this kind of error, after searching for possible resources still does not work.
Error:
java.lang.IllegalArgumentException: View android.widget.ExpandableListView{416b0bc8 VFED.VC. ......ID 0,0-480,0 #7f080005 app:id/lvExp} is not a drawer
Heres my code:
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
private DrawerLayout drawer;
private LinearLayout linear;
Button btn;
HashMap<String, List<String>> listDataChild;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
prepareListData();
btn = (Button)findViewById(R.id.button1);
linear = (LinearLayout)findViewById(R.id.linear);
expListView = (ExpandableListView) findViewById(R.id.lvExp);
drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(!drawer.isDrawerOpen(expListView))
{
drawer.openDrawer(expListView);
}
else
{
drawer.closeDrawer(expListView);
}
}
});
// get the listview
// preparing list data
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
FOR XML:
<?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"
android:background="#f4f4f4" >
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#000000"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<Button
android:id="#+id/button1"
android:layout_width="47dp"
android:layout_height="45dp"
android:background="#drawable/ic_home" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drawer"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ExpandableListView
android:id="#+id/lvExp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000" >
</ExpandableListView>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
</LinearLayout>

you are getting exception on if(!drawer.isDrawerOpen(expListView)) expListView list is not a drawer. thats why you are getting java.lang.IllegalArgumentException:
try this post you will get some idea.
for more information link

Related

WearableListView is always null when I changed my wear layout to WatchViewStub from BoxInsetLayout

I have an app that was using BoxInsetLayout but the round layout wasn't working out so I have to change it to WatchViewStub.
I changed to code so that it uses either a round layout or a square layout and that works find. There was a WearableListView inside the original layout file which was just one file. Now it is 3 files, the main one, and the round or square one. Now the listview is always null even though there are no compile time errors.
My onCreate in the main activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_select);
WatchViewStub stub = (WatchViewStub) findViewById(R.id.stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
#Override
public void onLayoutInflated(WatchViewStub watchViewStub) {
mRectangleBackground = (RelativeLayout) findViewById(R.id.rectLayout);
mRoundBackground = (RelativeLayout) findViewById(R.id.roundLayout);
}
});
WearableListView listView = (WearableListView) findViewById(R.id.list); // this is always null
listView.setHasFixedSize(true);
listView.setAdapter(new SportAdapter(this));
listView.setClickListener(this);
}
My view select xml file (the WatchViewStub)
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.WatchViewStub 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:rectLayout="#layout/view_select_square"
app:roundLayout="#layout/view_select_round"
android:keepScreenOn="true"
android:id="#+id/stub"
android:background="#color/green_forest">
</android.support.wearable.view.WatchViewStub>
The square layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
app:layout_box="all"
android:id="#+id/rectLayout">
<TextView
android:id="#+id/text_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:fontFamily="sans-serif-thin"
android:paddingBottom="5dp"
android:text="#string/text_select_sport"
android:textColor="#color/white"
android:textSize="26sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text_title"
android:background="#color/white"
android:padding="4dp">
<android.support.wearable.view.WearableListView
android:layout_centerInParent="true"
android:id="#+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none"
android:dividerHeight="0dp"/>
</RelativeLayout>
</RelativeLayout>
Whenever I call listView anything like setAdapter, setHasFixedSize, I get a null reference error. Why is my listView always null?
Here is the xml file when it was BoxInsetLayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:id="#+id/parent"
android:background="#color/green_forest">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
app:layout_box="all">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text_title"
android:text="#string/text_select_sport"
android:textSize="26sp"
android:textColor="#color/white"
android:fontFamily="sans-serif-thin"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:paddingBottom="5dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:padding="4dp"
android:layout_below="#+id/text_title">
<android.support.wearable.view.WearableListView
android:layout_centerInParent="true"
android:id="#+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none"
android:dividerHeight="0dp"/>
</RelativeLayout>
</RelativeLayout>
</android.support.wearable.view.BoxInsetLayout>
and the main activity before any changes
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_select);
WearableListView listView = (WearableListView) findViewById(R.id.list);
listView.setHasFixedSize(true);
listView.setAdapter(new SportAdapter(this));
listView.setClickListener(this);
}
So I fixed it by adding another method loadAdapter like this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_select);
WatchViewStub stub = (WatchViewStub) findViewById(R.id.stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
#Override
public void onLayoutInflated(WatchViewStub watchViewStub) {
mRectangleBackground = (RelativeLayout) findViewById(R.id.rectLayout);
mRoundBackground = (RelativeLayout) findViewById(R.id.roundLayout);
listView = (WearableListView) findViewById(R.id.list);
loadAdapter();
}
});
}
private void loadAdapter() {
listView.setHasFixedSize(true);
listView.setAdapter(new SportAdapter(this));
listView.setClickListener(this);
}
as seen in this example here https://gist.github.com/PomepuyN/c30760eaee1e58fdd8fa
ugh...

Listview on click event not working

i am trying to add on click listener in a listview but when clicked, no action. can you help me find what i did wrong?
This is adapted from one of the example in android tutorial
public class Main extends Activity {
private ListView menuListView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Inflate the menu items for use in the action bar
//getMenuInflater().inflate(R.menu.menu_main,menu);
//Get the Menu List from resources
menu = getResources().getStringArray(R.array.menu);
//get the drawer Layout
menuDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ArrayAdapter<String> itemAdapter = new ArrayAdapter<String>(this,R.layout.custom_menu_list,menu);
//get the list view
menuListView = (ListView) findViewById(R.id.listview);
menuListView.setAdapter(itemAdapter);
menuListView.setOnItemClickListener(new menuItemClickListener());
}
private class menuItemClickListener implements ListView.OnItemClickListener{
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("Check","clicked");
}
}
}//
}
This is the xml of the listview textview
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"
android:focusable="false"
android:focusableInTouchMode="false"
/>
This is the main xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"/>
<!-- The navigation drawer -->
<ListView android:id="#+id/listview"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/toastMsg"
android:text="Hello"/>
</android.support.v4.widget.DrawerLayout>
Modify you're main.xml file, remove the TextView and run the code. It works
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"/>
<!-- The navigation drawer -->
<ListView android:id="#+id/listview"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"/>
</android.support.v4.widget.DrawerLayout>

Android NavigationDrawer items don't click

I'm using Android NavigationDrawer without Listview items into slide menu, after creating and changing that slide menu items don't click and don't work to handle to click, for example this below code is my XML layout:
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/create_new_waybill"
android:gravity="center_vertical"
android:orientation="vertical"
android:layout_margin="5dp"
android:clickable="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_add_waybill"
android:layout_gravity="center"/>
<com.sample.app.Widgets.TextViewStyle
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="#dimen/normal_text_size"
android:text="#string/slidemenu_waybill"
app:fonttype="mjbeirut"
android:textColor="#000000"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/mainViewFragments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
In this XML I want to show Toast after clicking on create_new_waybill id.
my Activity
public class ActivityMain extends FragmentActivity {
private DrawerLayout mDrawerLayout;
private LinearLayout mSlideMenuContainer;
private ActionBarDrawerToggle mDrawerToggle;
private String[] items;
private UiFiller uiFiller;
private int currentSelectedSlideMenuItem;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
G.currentActivity = this;
/* Getting reference to the DrawerLayout */
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mSlideMenuContainer = (LinearLayout) findViewById(R.id.slide_menu);
LinearLayout create_new_waybill = (LinearLayout) findViewById(R.id.create_new_waybill);
create_new_waybill.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.e("ffffffffffff","aaaaaaa");
}
});
/* Initials UI widgets */
uiFiller = new UiFiller(getWindow().getDecorView());
/* Setting default fragment */
currentSelectedSlideMenuItem = 0;
updateFragment(currentSelectedSlideMenuItem);
}
}
Try setting these 3 attributes for ImageView and TextViewStyle:
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
and replace Log.e("ffffffffffff","aaaaaaa");
with:
Toast.makeText(view.getContext(), "Some text", Toast.LENGTH_SHORT).show();

ListView in Navigation Drawer DrawerLayout not populating

DrawerLayout activity_register.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal|center"
android:orientation="vertical" >
<TextView
android:id="#+id/msgView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<LinearLayout
android:id="#+id/sitrep_buttons_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal|center"
android:orientation="vertical">
<ImageView
android:id="#+id/sitrep_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:visibility="gone"
android:contentDescription="#string/desc"/>
</LinearLayout>
</LinearLayout>
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#999"/>
</android.support.v4.widget.DrawerLayout>
In my oncreate(Bundle savedInstanceState)
private ListView mDrawerList;
private String[] mActivities;
private String username = "";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
// mDrawerList = new ListView(RegisterActivity.this);
mActivities = getResources().getStringArray(R.array.menu_item_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerList.setBackgroundColor(0xFF00FF00);
Log.d(DTAG, "mDrawerList.getContentDescription: "+mDrawerList.getContentDescription());
Log.d(DTAG, "mDrawerList "+mDrawerList.equals(null));
Log.d(DTAG, "mActivities.length: "+mActivities.length);
for(int i = 0; i < mActivities.length; i++){
Log.d(DTAG, "mActivities: "+mActivities[i]);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, mActivities);
Log.d(DTAG, "adapter.getCount: "+adapter.getCount());
mDrawerList.setAdapter(adapter);
The Log shows that my array is populated properly.
The Navigation Drawer left_drawer (ListView) shows but is not populated. width changes if I change layout_width, and background color is matches setting as well. I've been looking at multiple posts to compare my code, but I can't see a problem with the code.
Any Ideas would be great!
Ok, here's something. I can't change any attributes of the ListView programmatically.
mDrawerList.setBackgroundColor(0xFF00FF00);
Has no effect. Background remains set to that set in the layout file.

How separating Lists with Headers in android?

I am trying that add section separator header for ListView in drawerLayout but i can not see separators and i just see titles.
This my code :
public class MainActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public Cursor cursor;
public Cursor cursorsex;
public ArrayList<String> array;
public ArrayList<String> arraysex;
private ArrayAdapter<String> listAdapter ;
private ArrayAdapter<String> listAdaptersex ;
private ListView mDrawerList;
private ListView mDrawerListsex;
.....
Connection to sqlite
.....
sql = db.openDataBase();
cursor = sql.rawQuery("SELECT Title FROM WebSite_CategoryBack WHERE ParentID=0;", null);
array = new ArrayList<String>();
while(cursor.moveToNext()){
Titel_Drawer = cursor.getString(cursor.getColumnIndex("Title"));
array.add(Titel_Drawer);
}
cursor.close();
cursorsex = sql.rawQuery("SELECT Title FROM WebSite_CategoryBack WHERE ParentID=0;", null);
arraysex = new ArrayList<String>();
while(cursorsex.moveToNext()){
Titel_Drawer = cursorsex.getString(cursorsex.getColumnIndex("Comment"));
arraysex.add(Titel_Drawer);
}
cursorsex.close();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerListsex = (ListView) findViewById(R.id.sex);
listAdapter = new ArrayAdapter<String>(this, R.layout.drawer_list,R.id.textView, array);
mDrawerList.setAdapter( listAdapter );
listAdaptersex = new ArrayAdapter<String>(this, R.layout.xxx,R.id.xxx, arraysex);
mDrawerListsex.setAdapter( listAdaptersex );
}
}
This is xxx.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/xxx"/>
This is drawer_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textView"/>
This is activity_main.xml:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:id="#+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="start">
<TextView
android:layout_width="240dp"
android:layout_height="25dp"
android:textSize="20sp"
android:gravity="center"
android:text="#string/prof"
android:background="#drawable/drawer_title_shape" />
<!-- The navigation drawer -->
<ir.makarem.extentions.ClearableEditText
android:id="#+id/SearchEdittxt"
android:drawableLeft="#drawable/ic_action_search"
android:layout_width="240dp"
android:layout_height="35dip"
android:background="#drawable/textlines"
android:gravity="right"
android:hint="#string/action_search" />
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#FFDDDDDD"/>
<ListView
android:id="#+id/sex"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#FFDDDDDD"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
For example i need to see look like this photo.
I add two TextView for Title and two ListView.
you have to use section header listview to achieve this functionality
Refrence link Section header listview
You need to set a divider for your ListView: (code example)
// white color for example
int[] clr = {0, 0xFFFFFFFF, 0};
listView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, clr));
listView.setDividerHeight(1); // set your desired height
Or set the divider in .xml:
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#FFFFFF"
android:dividerHeight="2px" >
</ListView>

Categories

Resources