Advertisement
Guest User

Untitled

a guest
Sep 19th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.18 KB | None | 0 0
  1. java.lang.RuntimeException: Unable to start activity ComponentInfo{id.wdharmana.doahindu/id.wdharmana.doahindu.MainActivity}: java.lang.NullPointerException
  2.  
  3. at id.wdharmana.doahindu.MainActivity.onCreate(MainActivity.java:42)
  4.  
  5. private CollapsingToolbarLayout ctb;
  6. private int mutedColor;
  7.  
  8. private DrawerLayout drawerLayout;
  9. private NavigationView navigationView;
  10. private Snackbar snackbar;
  11.  
  12. @Override
  13. protected void onCreate(Bundle savedInstanceState) {
  14. super.onCreate(savedInstanceState);
  15. setContentView(R.layout.activity_main);
  16.  
  17. /* Top toolbar */
  18. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  19. setSupportActionBar(toolbar);
  20.  
  21. /* Bottom toolbar. */
  22. Toolbar bottomToolbar = (Toolbar) findViewById(R.id.bottom_toolbar);
  23. bottomToolbar.inflateMenu(R.menu.menu_main);
  24. bottomToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
  25. @Override
  26. public boolean onMenuItemClick(MenuItem item) {
  27. String message = null;
  28. if (item.getItemId() == R.id.action_copy){
  29. message = "Copy clicked";
  30. }else if (item.getItemId() == R.id.action_cut){
  31. message = "Cut clicked";
  32. }else if (item.getItemId() == R.id.action_record){
  33. message = "Record clicked";
  34. }
  35.  
  36. Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
  37. return true;
  38. }
  39. });
  40.  
  41. RecyclerView recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
  42. recyclerView.setHasFixedSize(true);
  43. recyclerView.setLayoutManager(new LinearLayoutManager(this));
  44. // Add 8 cards
  45. MyAdapter adapter = new MyAdapter(new String[8]);
  46. recyclerView.setAdapter(adapter);
  47.  
  48. ctb = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
  49. ///* Define the image */
  50. // ImageView image = (ImageView) findViewById(R.id.image);
  51. ///* Decode bitmap from the image */
  52. // Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
  53. // R.drawable.full_image);
  54. ///* Generate palette from the image bitmap */
  55. // Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
  56. // @Override
  57. // public void onGenerated(Palette palette) {
  58. // mutedColor = palette.getMutedColor
  59. // (ContextCompat.getColor(MainActivity.this,
  60. // R.color.primary));
  61. // /* Set toolbar color from the palette */
  62. // ctb.setContentScrimColor(mutedColor);
  63. // }
  64. // });
  65. ctb.setContentScrimColor(ContextCompat.getColor(MainActivity.this, R.color.primary));
  66. ctb.setTitle(getString(R.string.app_name));
  67.  
  68. navigationView = (NavigationView) findViewById(R.id.nav_view);
  69. drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
  70.  
  71. // On click of menu icon on toolbar
  72. toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
  73. toolbar.setNavigationOnClickListener(new View.OnClickListener() {
  74. @Override
  75. public void onClick(View v) {
  76. drawerLayout.openDrawer(GravityCompat.START);
  77. }
  78. });
  79.  
  80. // On click of the navigation menu
  81. navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
  82. // This method will trigger on item Click of navigation menu
  83. @Override
  84. public boolean onNavigationItemSelected(MenuItem menuItem) {
  85. // Set item in checked state
  86. menuItem.setChecked(true);
  87.  
  88. //TODO: handle navigation
  89.  
  90. //Closing drawer on item click
  91. drawerLayout.closeDrawers();
  92. return true;
  93. }
  94. });
  95.  
  96. FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  97. fab.setOnClickListener(new View.OnClickListener() {
  98. @Override
  99. public void onClick(View v) {
  100. Snackbar.make(v, "Do something awesome?",
  101. Snackbar.LENGTH_LONG).show();
  102. }
  103. });
  104.  
  105.  
  106. }
  107.  
  108. /* Create RecylcerView Adapter. */
  109. public static class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
  110. private String[] mDataset;
  111.  
  112. public static class ViewHolder extends RecyclerView.ViewHolder {
  113. public View view;
  114. public TextView title;
  115. public ViewHolder(View v) {
  116. super(v);
  117. view = v;
  118. title = (TextView) v.findViewById(R.id.card_title);
  119. }
  120. }
  121.  
  122. public MyAdapter(String[] myDataset) {
  123. mDataset = myDataset;
  124. }
  125.  
  126. @Override
  127. public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  128. View cardview = LayoutInflater.from(parent.getContext())
  129. .inflate(R.layout.cardview, parent, false);
  130. return new ViewHolder(cardview);
  131. }
  132.  
  133. @Override
  134. public void onBindViewHolder(ViewHolder holder, int position) {
  135. holder.title.setText("Card " + (position + 1));
  136. }
  137.  
  138. @Override
  139. public int getItemCount() {
  140. return mDataset.length;
  141. }
  142. }
  143.  
  144. <android.support.v4.widget.DrawerLayout
  145. xmlns:android="http://schemas.android.com/apk/res/android"
  146. xmlns:app="http://schemas.android.com/apk/res-auto"
  147. android:id="@+id/drawer"
  148. android:layout_width="match_parent"
  149. android:layout_height="match_parent"
  150. android:fitsSystemWindows="true">
  151. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  152. xmlns:tools="http://schemas.android.com/tools"
  153. xmlns:app="http://schemas.android.com/apk/res-auto"
  154. android:layout_width="match_parent"
  155. android:layout_height="match_parent" tools:context=".MainActivity">
  156.  
  157. <android.support.design.widget.CoordinatorLayout
  158. android:id="@+id/main_content"
  159. android:layout_width="match_parent"
  160. android:layout_height="match_parent"
  161. android:layout_alignParentTop="true"
  162. android:layout_marginBottom="?attr/actionBarSize">
  163.  
  164. <android.support.design.widget.AppBarLayout
  165. android:id="@+id/appbar"
  166. android:layout_width="match_parent"
  167. android:layout_height="192dp">
  168. <android.support.design.widget.CollapsingToolbarLayout
  169. android:id="@+id/collapsing_toolbar"
  170. android:layout_width="match_parent"
  171. android:layout_height="match_parent"
  172. android:theme="@style/ThemeOverlay.AppCompat.Dark"
  173. app:layout_scrollFlags="scroll|exitUntilCollapsed">
  174. <ImageView
  175. android:id="@+id/image"
  176. android:layout_width="match_parent"
  177. android:layout_height="match_parent"
  178. android:background="@drawable/full_image"
  179. android:fitsSystemWindows="true"
  180. android:scaleType="centerCrop"
  181. app:layout_collapseMode="parallax" />
  182. <android.support.v7.widget.Toolbar
  183. android:id="@+id/toolbar"
  184. android:layout_width="match_parent"
  185. android:layout_height="?attr/actionBarSize"
  186. app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
  187. app:layout_collapseMode="pin" />
  188. </android.support.design.widget.CollapsingToolbarLayout>
  189. </android.support.design.widget.AppBarLayout>
  190.  
  191. <android.support.v7.widget.RecyclerView
  192. android:id="@+id/my_recycler_view"
  193. android:scrollbars="vertical"
  194. android:layout_width="match_parent"
  195. android:layout_height="match_parent"
  196. android:paddingTop="8dp"
  197. android:paddingBottom="8dp"
  198. android:clipToPadding="false"
  199. app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
  200.  
  201. <android.support.design.widget.FloatingActionButton
  202. android:id="@+id/fab"
  203. android:layout_width="wrap_content"
  204. android:layout_height="wrap_content"
  205. android:layout_marginBottom="16dp"
  206. android:layout_marginRight="16dp"
  207. android:layout_gravity="right|bottom"
  208. android:tint="@android:color/white"
  209. android:src="@drawable/ic_add"/>
  210.  
  211.  
  212. </android.support.design.widget.CoordinatorLayout>
  213.  
  214. <android.support.v7.widget.Toolbar
  215. android:id="@+id/bottom_toolbar"
  216. android:layout_height="?attr/actionBarSize"
  217. android:layout_width="match_parent"
  218. android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
  219. android:background="?attr/colorPrimaryDark"
  220. android:layout_alignParentBottom="true"/>
  221. </RelativeLayout>
  222.  
  223. <android.support.design.widget.NavigationView
  224. android:id="@+id/nav_view"
  225. android:layout_width="wrap_content"
  226. android:layout_height="match_parent"
  227. android:layout_gravity="start"
  228. android:background="#ffffff"
  229. android:clickable="true"
  230. app:headerLayout="@layout/navheader"
  231. app:menu="@menu/menu_navigation"
  232. app:itemBackground="?attr/selectableItemBackground"/>
  233.  
  234. <android.support.v7.widget.CardView
  235. xmlns:android="http://schemas.android.com/apk/res/android"
  236. xmlns:tools="http://schemas.android.com/tools"
  237. xmlns:card_view="http://schemas.android.com/apk/res-auto"
  238. android:id="@+id/card_view"
  239. android:layout_gravity="center"
  240. android:layout_width="match_parent"
  241. android:layout_height="96dp"
  242. android:layout_marginLeft="16dp"
  243. android:layout_marginRight="16dp"
  244. android:layout_marginTop="8dp"
  245. android:layout_marginBottom="8dp"
  246. card_view:contentPadding="8dp"
  247. android:clickable="true"
  248. android:foreground="?attr/selectableItemBackground">
  249. <TextView
  250. android:id="@+id/card_title"
  251. android:layout_width="match_parent"
  252. android:layout_height="wrap_content"
  253. android:textAppearance="@style/TextAppearance.AppCompat.Title"
  254. tools:text="Title text"/>
  255.  
  256. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  257. android:layout_width="match_parent"
  258. android:layout_height="222dp"
  259. android:background="?attr/colorPrimaryDark"
  260. android:padding="16dp"
  261. android:orientation="vertical">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement