Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
EventActivity Drawer Issues
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red_light"
android:orientation="vertical"
android:id="@+id/drawerLayout">
<ListView
android:id="@+id/eventList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@android:color/transparent"
android:dividerHeight="@dimen/activity_horizontal_margin"
android:padding="@dimen/activity_horizontal_margin" />
<include
layout="@layout/drawer_layout"/>
</android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="280dp"
android:layout_height="match_parent"
android:id="@+id/drawerPane"
android:layout_gravity="start"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView
android:id="@+id/navList"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_below="@+id/profileBox"
android:choiceMode="singleChoice"
android:background="#ffffffff" />
<RelativeLayout
android:id="@+id/profileBox"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/material_blue_grey_800"
android:padding="8dp" >
<ImageView
android:id="@+id/avatar"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_launcher"
android:layout_marginTop="15dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/avatar"
android:orientation="vertical" >
<TextView
android:id="@+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rishabh"
android:textColor="#fff"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="4dp"
android:text="View Profile"
android:textColor="#fff"
android:textSize="12sp" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
package com.appex.tryproject;
import android.content.res.Configuration;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import com.appex.tryproject.Resources.Constants;
import com.appex.tryproject.Resources.DrawerItem;
import com.appex.tryproject.Resources.EventAdapter;
import com.appex.tryproject.Resources.RowItem;
import com.appex.tryproject.Resources.DrawerListAdapter;
import java.util.ArrayList;
import java.util.List;
public class EventActivity extends ActionBarActivity{
String events[]= Constants.events,locations[]=Constants.locations,time[]=Constants.time,date[]=Constants.date,contact[]=Constants.contact;
ListView eventView, mDrawerList;
List<RowItem> eventItems;
ActionBarDrawerToggle mDrawerToggle;
String msg="clicked";
android.support.v7.app.ActionBar actionBar;
DrawerLayout mDrawerLayout;
ArrayList<DrawerItem> mDrawerItems = new ArrayList<DrawerItem>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.toolbar_event);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_event);
setSupportActionBar(toolbar);
actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
mDrawerItems.add(new DrawerItem("Home", "Meetup destination", R.drawable.ic_date));
mDrawerItems.add(new DrawerItem("Preferences", "Change your preferences", R.drawable.ic_location));
mDrawerItems.add(new DrawerItem("About", "Get to know about us", R.drawable.ic_contact));
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
toolbar, R.string.drawer_opened,
R.string.drawer_closed);
mDrawerList = (ListView) findViewById(R.id.navList);
DrawerListAdapter dradapter = new DrawerListAdapter(this, mDrawerItems);
mDrawerList.setAdapter(dradapter);
mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(),msg,Toast.LENGTH_SHORT).show();
}
});
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
eventItems = new ArrayList<RowItem>();
for (int i = 0; i < events.length; i++) {
RowItem item = new RowItem(events[i], locations[i], time[i], date[i], contact[i]);
eventItems.add(item);
}
mDrawerLayout.setDrawerListener(mDrawerToggle);
eventView = (ListView) findViewById(R.id.eventList);
EventAdapter adapter = new EventAdapter(this, eventItems);
eventView.setAdapter(adapter);
eventView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Toast toast = Toast.makeText(getApplicationContext(),
"Item " + (position + 1) + ": " + eventItems.get(position),
Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
}
});
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@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_event, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appex.tryproject/com.appex.tryproject.EventActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5135)
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:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.support.v7.app.ActionBarDrawerToggle.syncState(ActionBarDrawerToggle.java:240)
**at com.appex.tryproject.EventActivity.onPostCreate(EventActivity.java:87)**
(Line 87 is mDrawerToggle.syncState();)
at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1150)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2220)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:212)
            at android.app.ActivityThread.main(ActivityThread.java:5135)
            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:878)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
            at dalvik.system.NativeStart.main(Native Method)
@anuraagbaishya

This comment has been minimized.

Copy link
Owner Author

@anuraagbaishya anuraagbaishya commented Jun 11, 2015

Error on Line 87 in EventActivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment