How to correctly use a snackbar in Android - java

I have created a simple counter application for Android. I have just started using support libraries and just to test it out, I wanted to show a snackbar which says Hello. Here is my code in the MainActivity.java file :
package com.mapsup.counter;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.google.android.material.snackbar.Snackbar;
public class MainActivity extends Activity {
long count=0;
TextView tv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
SharedPreferences sp=getApplicationContext().getSharedPreferences("preferences",Context.MODE_PRIVATE);
count=sp.getLong("count",0);
tv=findViewById(R.id.counter);
tv.setText(String.valueOf(count));
//Create and display a snackbar
Snackbar snackbar = Snackbar.make(tv,"Hello",Snackbar.LENGTH_LONG);
snackbar.show();
}
public void increase(View view) {
++count;
tv.setText(String.valueOf(count));
}
public void decrease(View view) {
if(count>0) {
--count;
tv.setText(String.valueOf(count));
}
}
public void reset(View view) {
count=0;
tv.setText("0");
}
#Override
public void onStop() {
super.onStop();
Context ctx=getApplicationContext();
SharedPreferences sp=ctx.getSharedPreferences("preferences",Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sp.edit();
editor.putLong("count",count);
editor.apply();
}
}
Here is the layout main_layout.xml file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0031A0"
android:orientation="vertical"
android:padding="20dp"
android:id="#+id/root">
<TextView
android:id="#+id/counter"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="20dp"
android:layout_weight="1"
android:background="#B2FFFFFF"
android:gravity="center"
android:textSize="36sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="increase"
android:text="#string/add"
android:textSize="30sp" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="decrease"
android:text="#string/subt"
android:textSize="30sp" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="reset"
android:text="#string/reset"
android:textAllCaps="false"
android:textSize="30sp" />
</LinearLayout>
When I am running the app, the app crashes. The logcat shows this as the error message :
2020-02-03 00:20:10.015 12849-12849/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mapsup.counter, PID: 12849
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mapsup.counter/com.mapsup.counter.MainActivity}: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at com.google.android.material.snackbar.Snackbar.make(Snackbar.java:164)
at com.mapsup.counter.MainActivity.onCreate(MainActivity.java:23)
at android.app.Activity.performCreate(Activity.java:6712)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:531)
at android.widget.TextView.<init>(TextView.java:805)
at android.widget.TextView.<init>(TextView.java:727)
at android.widget.TextView.<init>(TextView.java:723)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
at android.view.LayoutInflater.createView(LayoutInflater.java:645) 
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
at com.google.android.material.snackbar.Snackbar.make(Snackbar.java:164) 
at com.mapsup.counter.MainActivity.onCreate(MainActivity.java:23) 
at android.app.Activity.performCreate(Activity.java:6712) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:203) 
at android.app.ActivityThread.main(ActivityThread.java:6251) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924) 
The app runs all fine if I remove the snackbar code.
According to my thinking, creating a snackbar is the same as creating a toast, we just need to replace Toast with Snackbar. Is this correct?
What is my mistake and how to properly use a snackbar?

Please replace tv to rootLayout in Snackbar.make(llRootLayout,"Hello",Snackbar.LENGTH_LONG); as below.
public class MainActivity extends Activity {
long count=0;
TextView tv;|
LinearLayout llRootLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
SharedPreferences sp=getApplicationContext().getSharedPreferences("preferences",Context.MODE_PRIVATE);
count=sp.getLong("count",0);
tv=findViewById(R.id.counter);
llRootLayout=findViewById(R.id.root);
tv.setText(String.valueOf(count));
//Create and display a snackbar
Snackbar snackbar=Snackbar.make(llRootLayout,"Hello",Snackbar.LENGTH_LONG);
snackbar.show();
}
public void increase(View view) {
++count;
tv.setText(String.valueOf(count));
}
public void decrease(View view) {
if(count>0) {
--count;
tv.setText(String.valueOf(count));
}
}
public void reset(View view) {
count=0;
tv.setText("0");
}
#Override
public void onStop() {
super.onStop();
Context ctx=getApplicationContext();
SharedPreferences sp=ctx.getSharedPreferences("preferences",Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sp.edit();
editor.putLong("count",count);
editor.apply();
}
}

Related

Android: Error inflating PreferenceScreen

I've seen a few other similar references to this issue, however have not yet found a solution to my issue.
I used to use android.preference.Preference however have recently moved over to androidx in order to use a SeekBarPreference.
Now, when I try to inflate the Preference screen I get the following error:
2021-11-17 20:57:20.623 18270-18270/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.project.test, PID: 18270
android.view.InflateException: Binary XML file line #1: Error inflating class (not found)android.support.v7.preference.PreferenceScreen
at androidx.preference.PreferenceInflater.createItemFromTag(PreferenceInflater.java:287)
at androidx.preference.PreferenceInflater.inflate(PreferenceInflater.java:151)
at androidx.preference.PreferenceInflater.inflate(PreferenceInflater.java:109)
at androidx.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:216)
at androidx.preference.PreferenceFragmentCompat.setPreferencesFromResource(PreferenceFragmentCompat.java:377)
at com.project.test.SettingsFragment.onCreatePreferences(SettingsFragment.java:33)
at androidx.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:160)
at com.project.test.SettingsFragment.onCreate(SettingsFragment.java:25)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2684)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1175)
at androidx.fragment.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1255)
at androidx.fragment.app.FragmentTransition.calculateFragments(FragmentTransition.java:1138)
at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:136)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1989)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1947)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.ClassNotFoundException: android.support.v7.preference.PreferenceScreen
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at androidx.preference.PreferenceInflater.createItem(PreferenceInflater.java:214)
at androidx.preference.PreferenceInflater.createItemFromTag(PreferenceInflater.java:277)
at androidx.preference.PreferenceInflater.inflate(PreferenceInflater.java:151) 
at androidx.preference.PreferenceInflater.inflate(PreferenceInflater.java:109) 
at androidx.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:216) 
at androidx.preference.PreferenceFragmentCompat.setPreferencesFromResource(PreferenceFragmentCompat.java:377) 
at com.project.test.SettingsFragment.onCreatePreferences(SettingsFragment.java:33) 
at androidx.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:160) 
at com.project.test.SettingsFragment.onCreate(SettingsFragment.java:25) 
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2684) 
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280) 
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1175) 
at androidx.fragment.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1255) 
at androidx.fragment.app.FragmentTransition.calculateFragments(FragmentTransition.java:1138) 
at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:136) 
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1989) 
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1947) 
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849) 
at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413) 
at android.os.Handler.handleCallback(Handler.java:938) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loopOnce(Looper.java:201) 
at android.os.Looper.loop(Looper.java:288) 
at android.app.ActivityThread.main(ActivityThread.java:7839) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 
Caused by: java.lang.ClassNotFoundException: android.support.v7.preference.PreferenceScreen
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:454) 
at androidx.preference.PreferenceInflater.createItem(PreferenceInflater.java:214) 
at androidx.preference.PreferenceInflater.createItemFromTag(PreferenceInflater.java:277) 
at androidx.preference.PreferenceInflater.inflate(PreferenceInflater.java:151) 
at androidx.preference.PreferenceInflater.inflate(PreferenceInflater.java:109) 
at androidx.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:216) 
at androidx.preference.PreferenceFragmentCompat.setPreferencesFromResource(PreferenceFragmentCompat.java:377) 
at com.project.test.SettingsFragment.onCreatePreferences(SettingsFragment.java:33) 
at androidx.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:160) 
at com.project.test.SettingsFragment.onCreate(SettingsFragment.java:25) 
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2684) 
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280) 
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1175) 
at androidx.fragment.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1255) 
at androidx.fragment.app.FragmentTransition.calculateFragments(FragmentTransition.java:1138) 
at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:136) 
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1989) 
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1947) 
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849) 
at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413) 
at android.os.Handler.handleCallback(Handler.java:938) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loopOnce(Looper.java:201) 
at android.os.Looper.loop(Looper.java:288) 
at android.app.ActivityThread.main(ActivityThread.java:7839) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 
An excerpt of my SettingsFragment.java file (error is reported on the setPreferencesFromResource line):
public class SettingsFragment extends PreferenceFragmentCompat {
Utilities utils = new Utilities();
Context context = ProjectGlobal.getAppContext();
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor settingsEditor = settings.edit()
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.pref_general, rootKey);
Preference pfPermissionsReset = findPreference("permissionsPrompt");
Preference pfBatterySaving = findPreference("batteryPrompt");
final SeekBarPreference pfVolumeValue = (SeekBarPreference) findPreference("sbVolume");
final SwitchPreference pfGlobalVolume = (SwitchPreference) findPreference("chkUseGlobalVolume");
//init global volume control
pfVolumeValue.setMax(100);
pfVolumeValue.setMin(0);
From my pref_general.xml preference layout:
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.PreferenceCategory
android:summary="App Settings"
android:title="GENERAL" />
<android.support.v7.preference.SwitchPreference
android:key="chkNotificationListener"
android:summary="This option allows you to disable the app without uninstalling the application. [Default: On]"
android:title="Notification Listener"
android:defaultValue="true"
/>
<android.support.v7.preference.SwitchPreference
android:key="chkHideBanner"
android:summary="This option hides the banner notification at the top of the screen. Please note, this may impact the reliability of the application if disabled! [Default: Off]"
android:title="Hide Banner Notification"
android:defaultValue="false"
/>
<android.support.v7.preference.Preference android:title="Check Battery Saving"
android:key="batteryPrompt"
android:summary="Tap here to check that the app is allowed to run in the background/during startup on your device" />
<android.support.v7.preference.PreferenceCategory
android:summary="Audio"
android:title="AUDIO"/>
<android.support.v7.preference.SwitchPreference
android:key="chkOnlyUseSpeaker"
android:summary="This option will attempt to play audio alerts from the device loudspeaker only [Default: Off]"
android:title="Only Use Speaker"
android:defaultValue="false"
/>
<android.support.v7.preference.SwitchPreference
android:key="chkUseGlobalVolume"
android:summary="This option will override any volume settings set in each rule [Default: Off]"
android:title="Use Global Volume"
android:defaultValue="false"
/>
<android.support.v7.preference.SeekBarPreference
android:key="sbVolume"
android:title="Global Volume"
android:dependency="chkUseGlobalVolume"
android:max="100"
android:defaultValue="50"
/>
/>
<android.support.v7.preference.PreferenceCategory
android:summary="Security"
android:title="SECURITY"/>
<android.support.v7.preference.Preference android:title="Check Permissions"
android:key="#string/permissionsPrompt"
android:summary="Tap here to re-check permissions" />
</android.support.v7.preference.PreferenceScreen>
From my Launcher.java:
public class Launcher extends AppCompatActivity implements SettingsFragment.OnFragmentInteractionListener,RuleFragment.OnFragmentInteractionListener,HelpFragment.OnFragmentInteractionListener {
RuleFragment ruleFragment = new RuleFragment();
SettingsFragment prefsFragment = new SettingsFragment();
HelpFragment helpFragment = new HelpFragment();
Utilities utils = new Utilities();
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
getSupportFragmentManager().beginTransaction().remove(helpFragment).commit();
getSupportFragmentManager().beginTransaction().remove(prefsFragment).commit();
getSupportFragmentManager().beginTransaction().replace(R.id.contentFrame,ruleFragment).commit();
return true;
case R.id.navigation_settings:
getSupportFragmentManager().beginTransaction().remove(ruleFragment).commit();
getSupportFragmentManager().beginTransaction().remove(helpFragment).commit();
getSupportFragmentManager().beginTransaction().replace(R.id.contentFrame,prefsFragment).commit();
return true;
case R.id.navigation_help:
getSupportFragmentManager().beginTransaction().remove(prefsFragment).commit();
getSupportFragmentManager().beginTransaction().remove(ruleFragment).commit();
getSupportFragmentManager().beginTransaction().replace(R.id.contentFrame,helpFragment).commit();
return true;
}
return false;
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Launcher.context = getApplicationContext();
Utilities utils = new Utilities();
//initiate home screen
setContentView(R.layout.main);
getSupportFragmentManager().beginTransaction().replace(R.id.contentFrame,ruleFragment).commit();
}
My main.xml layout for Launcher:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/main_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_above="#+id/navigation"
app:titleTextColor="#color/Black"
>
<FrameLayout
android:id="#+id/contentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:menu="#menu/navigation" />
</RelativeLayout>
Managed to solve this. It was because I hadn't updated android.support.v7.preference within pref_general.xml to androidx.preference.
After doing this, it worked fine!

videoview.setVideoUri shows null pointer exception

So I have a VideoView but when I try to play video (which is in my res/raw folder)it gives me null pointer exception. I tried using video.setVideoUri(uri) and also video.setVideoPath(path) but it still shows null pointer exception.
Activity:
public class Player extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
VideoView videoView=findViewById(R.id.videoView);
String path="android.resource://"+getPackageName()+"/"+R.raw.playthis;
Uri uri=Uri.parse(path);
videoView.setVideoPath(uri.getPath());
}
public void goBackVideo(View view){
finish();
}
}
xml for VideoView:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/VideoPlayerFrameLayout" android:background="#drawable/player_video_pause">
<VideoView android:layout_width="match_parent" android:layout_height="match_parent"
android:id="#+id/videoView"/>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:src="#drawable/player_icon_play" android:onClick="setPlayORpause"
android:id="#+id/PauseButton" android:background="#fff"/>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="left|center" android:layout_marginLeft="160dp"
android:src="#drawable/player_icon_prev" android:id="#+id/PrevButton" android:background="#fff"/>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="right|center" android:layout_marginRight="160dp"
android:src="#drawable/player_icon_next" android:id="#+id/NextButton" android:background="#fff"/>
<ImageButton
android:layout_width="46dp"
android:layout_height="34dp"
android:id="#+id/backPressButton"
android:rotation="180" android:backgroundTint="#fff"
android:background="#null"
android:src="#drawable/settings_icon_back"
android:layout_gravity="left"
android:onClick="goBackVideo" android:drawingCacheQuality="high"/>
</FrameLayout>
Logcat:
2020-10-29 06:58:50.965 13640-13640/com.testapp.test3 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.testapp.test3, PID: 13640
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testapp.test3/com.testapp.test3.VideoPlayer}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.VideoView.setVideoPath(java.lang.String)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2887)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2965)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1669)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:192)
at android.app.ActivityThread.main(ActivityThread.java:6702)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.VideoView.setVideoPath(java.lang.String)' on a null object reference
at com.testapp.test3.VideoPlayer.onCreate(VideoPlayer.java:26)
at android.app.Activity.performCreate(Activity.java:7115)
at android.app.Activity.performCreate(Activity.java:7106)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2840)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2965) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1669) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:192) 
at android.app.ActivityThread.main(ActivityThread.java:6702) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826) 
Do I need to set up a content provider before I can play any video?
How do I fix this?
EDIT:
Now i get another error
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
final VideoView videoView=findViewById(R.id.videoView);
Uri uri=Uri.parse("content://" +"sdcard/"+Environment.DIRECTORY_DOWNLOADS+"/"+"playthis.mp4");
MediaController mediaController=new MediaController(this);
videoView.setMediaController(mediaController);
mediaController.setAnchorView(videoView);
videoView.setVideoURI(uri);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
videoView.seekTo(0);
videoView.start();
}
});
}
logcat:
2020-10-29 07:51:39.371 27420-27420/com.testapp.test3 E/ActivityThread: Failed to find provider info for sdcard
2020-10-29 07:51:39.371 27420-27420/com.testapp.test3 W/MediaPlayer: Couldn't open content://sdcard/Download/playthis.mp4: java.io.FileNotFoundException: No content provider: content://sdcard/Download/playthis.mp4
2020-10-29 07:51:39.375 27420-27420/com.testapp.test3 E/MediaPlayerNative: Unable to create media player
2020-10-29 07:51:39.381 27420-27420/com.testapp.test3 W/VideoView: Unable to open content: content://sdcard/Download/playthis.mp4
java.io.IOException: setDataSource failed.: status=0x80000000
at android.media.MediaPlayer.nativeSetDataSource(Native Method)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1181)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1169)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1087)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1108)
at android.widget.VideoView.openVideo(VideoView.java:399)
at android.widget.VideoView.-wrap0(Unknown Source:0)
at android.widget.VideoView$7.surfaceCreated(VideoView.java:678)
at android.view.SurfaceView.updateSurface(SurfaceView.java:710)
at android.view.SurfaceView$2.onPreDraw(SurfaceView.java:145)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2427)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1446)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6954)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:925)
at android.view.Choreographer.doCallbacks(Choreographer.java:737)
at android.view.Choreographer.doFrame(Choreographer.java:669)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:911)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:192)
at android.app.ActivityThread.main(ActivityThread.java:6702)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
You should add a contentView on your activity onCreate So change your onCreate Like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout_name) // Add this line,
VideoView videoView=findViewById(R.id.videoView);
String path="android.resource://"+getPackageName()+"/"+R.raw.playthis;
Uri uri=Uri.parse(path);
videoView.setVideoPath(uri.getPath());
}
After that you should check null video path, like
// If path is not null then set it to your videoView.
if(uri.getPath() != null) {
videoView.setVideoPath(uri.getPath());
}

Trying make Android Uber app clone from Edmtdev, java.lang.RuntimeException: Unable to start activity ComponentInfo,android.view.InflateException

I am a newbie in Android development
Logcat:
com.example.androuber E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.androuber, PID: 19270
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androuber/com.example.androuber.Welcome}: android.view.InflateException: Binary XML file line #25: Binary XML file line #25: Error inflating class com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3430)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199)
at android.os.Handler.dispatchMessage(Handler.java:112)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
Caused by: android.view.InflateException: Binary XML file line #25: Binary XML file line #25: Error inflating class com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:658)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:874)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:877)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:877)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
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 com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:498)
at com.android.internal.policy.HwPhoneWindow.setContentView(HwPhoneWindow.java:342)
at android.app.Activity.setContentView(Activity.java:2941)
at com.example.androuber.Welcome.onCreate(Welcome.java:78)
at android.app.Activity.performCreate(Activity.java:7458)
at android.app.Activity.performCreate(Activity.java:7448)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1286)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3409)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199)
at android.os.Handler.dispatchMessage(Handler.java:112)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
This the Welcome.java.78:
setContentView(R.layout.activity_welcome);
activity_welcome:
<?xml version="1.0" encoding="utf-8"?>
<fragment 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:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Welcome"
class="com.google.android.gms.maps.SupportMapFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:weightSum="10"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
android:id="#+id/location_switch"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"
app:icon_release="#drawable/ic_location_off"
app:icon_press="#drawable/ic_location_on"
app:base_release_color="#color/baseReleaseColor"
app:base_press_color="#color/basePressColor"
app:ball_release_color="#color/ballReleaseColor"
app:ball_press_color="#android:color/white"
/>
</LinearLayout>
</RelativeLayout>
</fragment>
OnCreate of Welcome.java where are occurring:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
//init view
location_switch = (MaterialAnimatedSwitch) findViewById(R.id.location_switch);
location_switch.setOnCheckedChangeListener(new MaterialAnimatedSwitch.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(boolean isOnline) {
if (isOnline){
startLocationUpdate();
displayLocation();
Snackbar.make(mapFragment.getView(),"You Are Online",Snackbar.LENGTH_SHORT)
.show();
}
else {
stopLocationUpdates();
mCurrent.remove();
Snackbar.make(mapFragment.getView(),"You Are Offline",Snackbar.LENGTH_SHORT)
.show();
}
}
});
drivers = FirebaseDatabase.getInstance().getReference("Drivers");
geoFire = new GeoFire(drivers);
setUpLocation();
}
mainactivity Login block
private void showLoginDialog() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle("SIGN IN");
dialog.setMessage("Please Use Email To sign in");
LayoutInflater inflater = LayoutInflater.from(this);
View login_layout = inflater.inflate(R.layout.layout_login,null);
final MaterialEditText edtEmail = (MaterialEditText) login_layout.findViewById(R.id.edtEmail);
final MaterialEditText edtPassword = (MaterialEditText) login_layout.findViewById(R.id.edtPassword);
dialog.setView(login_layout);
// set Button
dialog.setPositiveButton("SIGN IN", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//set disable button sign in if in processing
btnSignUP.setEnabled(false);
//check validation
if (TextUtils.isEmpty(edtEmail.getText().toString())) {
Snackbar.make(rootLayout, "Please Enter Email Address", Snackbar.LENGTH_SHORT)
.show();
return;
}
if (TextUtils.isEmpty(edtPassword.getText().toString())) {
Snackbar.make(rootLayout, "Please Enter Password", Snackbar.LENGTH_SHORT)
.show();
return;
}
if (edtPassword.getText().toString().length() < 6) {
Snackbar.make(rootLayout, "Password too short!!!", Snackbar.LENGTH_SHORT)
.show();
return;
}
final android.app.AlertDialog waitingDialog = new SpotsDialog.Builder().setContext(MainActivity.this).build();
waitingDialog.show();
//login
auth.signInWithEmailAndPassword(edtEmail.getText().toString(),edtPassword.getText().toString())
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
#Override
public void onSuccess(AuthResult authResult) {
waitingDialog.dismiss();
startActivity(new Intent(MainActivity.this,Welcome.class));
finish();
}
}) .addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
waitingDialog.dismiss();
Snackbar.make(rootLayout,"Failed "+e.getMessage(),Snackbar.LENGTH_SHORT)
.show();
//Activate Sign up Button
btnSignUP.setEnabled(true);
}
});
}
});
dialog.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialog.show();
}
<com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
android:id="#+id/location_switch"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"
app:icon_release="#drawable/ic_location_off"
app:icon_press="#drawable/ic_location_on"
app:base_release_color="#color/baseReleaseColor"
app:base_press_color="#color/basePressColor"
app:ball_release_color="#color/ballReleaseColor"
app:ball_press_color="#android:color/white"
/>
I think you have used some attribute which is not provided by this library, remove all the custom attributes and check if it working or not, then you can apply your attribute one by one.
Check this : Error inflating MaterialAnimatedSwitch
I think it already has been answered here.
You added lib to the project?:
In project build.gradle :
allprojects {
repositories {
maven {
url "http://dl.bintray.com/glomadrian/maven"
}
}
}
In app/build.gradle:
implementation 'com.github.glomadrian:MaterialAnimatedSwitch:1.1#aar'

Error inflating class MaterialEditText

I am new to android development. Please help me in identifying the issue in my code. My code is getting into InflateException.
Please help me.
My code is existing with error related to MaterialEditText class and I have searched for the solution but till now didn't get the working solution.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_vertical"
tools:context="com.android.appgallery.quizworld.MainActivity">
<ImageView
android:layout_marginBottom="20dp"
android:layout_centerHorizontal="true"
android:src="#drawable/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/wrap_login"
/>
<RelativeLayout
android:id="#+id/wrap_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="8dp"
>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/info_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:com.rengwuxian.materialedittext="http://schemas.android.com/tools"
android:layout_margin="8dp"
app:cardElevation="4dp">
<LinearLayout
android:padding="16dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.rengwuxian.materialedittext:MaterialEditText
android:id="#+id/edtUser"
android:hint="User Name"
android:textColorHint="#color/colorPrimary"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:met_baseColor="#color/colorPrimary"
app:met_floatingLabel="highlight"
app:met_primaryColor="#color/colorPrimary"
app:met_singleLineEllipsis="true"
/>
<com.rengwuxian.materialedittext:MaterialEditText
android:id="#+id/edtPassword"
android:hint="Password"
android:textColorHint="#color/colorPrimary"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:met_baseColor="#color/colorPrimary"
app:met_floatingLabel="highlight"
app:met_primaryColor="#color/colorPrimary"
app:met_singleLineEllipsis="true"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_below="#id/info_login"
android:orientation="horizontal"
android:weightSum="2"
android:layout_margin="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn_sign_up"
android:text="Sign Up"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btn_sign_in"
android:text="Sign In"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="MyButton" parent="Theme.AppCompat.Light">
<item name="colorControlHighlight">#1CB3BC</item>
</style>
</resources>
MainActivity
package com.android.appgallery.quizworld;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.android.appgallery.quizworld.BroadcastReceiver.AlarmReceiver;
import com.android.appgallery.quizworld.Common.Common;
import com.android.appgallery.quizworld.Model.User;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.rengwuxian.materialedittext.MaterialEditText;
import java.util.Calendar;
public class MainActivity extends AppCompatActivity {
MaterialEditText edtNewUser,edtNewPassword,edtNewEmail; //For Sign Up
MaterialEditText edtUser,edtPassword; //For Login
Button btnSignUp,btnSignIn;
FirebaseDatabase database;
DatabaseReference users;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
try {
setContentView(R.layout.activity_main);
}catch(Exception e){
//InflateException ex=new InflateException(parser.getPositionDescription()+" "+e.getMessage());
InflateException ex=new InflateException(e.getMessage());
ex.initCause(e);
throw ex;
}
registerAlarm();
database= FirebaseDatabase.getInstance();
users=database.getReference("Users");
edtUser=(MaterialEditText) findViewById(R.id.edtUser);
edtPassword=(MaterialEditText)findViewById(R.id.edtPassword);
btnSignIn= (Button) findViewById(R.id.btn_sign_in);
btnSignUp= (Button) findViewById(R.id.btn_sign_up);
btnSignUp.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
showSignUpDialog();
}
});
btnSignIn.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
signIn(edtUser.getText().toString(),edtPassword.getText().toString());
}
});
}
private void registerAlarm() {
Calendar calendar=Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,9);
calendar.set(Calendar.MINUTE,40);
calendar.set(Calendar.SECOND,0);
Intent intent=new Intent(MainActivity.this, AlarmReceiver.class);
PendingIntent pendingIntent=PendingIntent.getBroadcast(MainActivity.this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager)this.getSystemService(this.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pendingIntent);
}
private void signIn(final String user, final String pwd){
users.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.child(user).exists()){
if(!user.isEmpty()){
User login=dataSnapshot.child(user).getValue(User.class);
if(login.getPassword().equals(pwd)){
Intent homeActivity=new Intent(MainActivity.this,Home.class);
Common.currentUser= login;
startActivity(homeActivity);
finish();
}else{
Toast.makeText(MainActivity.this,"Wrong Password",Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(MainActivity.this,"Please enter your user name.",Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(MainActivity.this,"User does not exist",Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private void showSignUpDialog(){
AlertDialog.Builder alertDialog= new AlertDialog.Builder(MainActivity.this);
alertDialog.setTitle("Sign Up");
alertDialog.setMessage("Please fill full information");
LayoutInflater inflater=this.getLayoutInflater();
View sign_up_layout = inflater.inflate(R.layout.sign_up_layout,null);
edtNewUser=(MaterialEditText) sign_up_layout.findViewById(R.id.edtNewUserName);
edtNewPassword=(MaterialEditText) sign_up_layout.findViewById(R.id.edtNewPassword);
edtNewEmail=(MaterialEditText) sign_up_layout.findViewById(R.id.edtNewEmail);
alertDialog.setView(sign_up_layout);
//Check for the icon
alertDialog.setIcon(R.drawable.ic_account_circle_black_24dp);
alertDialog.setNegativeButton("NO",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialogInterface, int i){
dialogInterface.dismiss();
}
});
alertDialog.setPositiveButton("YES",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialogInterface, int i) {
final User user = new User(edtNewUser.getText().toString(), edtNewPassword.
getText().toString(), edtNewEmail.getText().toString());
users.addListenerForSingleValueEvent(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.child(user.getUserName()).exists())
Toast.makeText(MainActivity.this, "User already exists!!!", Toast.LENGTH_SHORT).show();
else {
users.child(user.getUserName()).setValue(user);
Toast.makeText(MainActivity.this, "User registration successful!!!", Toast.LENGTH_SHORT).show();
}
}
public void onCancelled(DatabaseError databaseError) {
}
});
dialogInterface.dismiss();
}
});
alertDialog.show();
}
}
Error Snippet:
01-18 23:14:13.656 23773-23773/? I/art: Late-enabling -Xcheck:jni
01-18 23:14:13.726 23773-23773/com.android.appgallery.quizworld D/LenovoAppIconTheme: ExtraResources;cleanCachedIcon;clear cache..
01-18 23:14:14.049 23773-23773/com.android.appgallery.quizworld W/System: ClassLoader referenced unknown path:
/data/app/com.android.appgallery.quizworld-2/lib/arm
01-18 23:14:14.079 23773-23773/com.android.appgallery.quizworld D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping
initialization.
01-18 23:14:14.095 23773-23773/com.android.appgallery.quizworld W/InstanceID/Rpc: Found 10014
01-18 23:14:14.102 23773-23773/com.android.appgallery.quizworld D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping
initialization.
01-18 23:14:14.144 23773-23773/com.android.appgallery.quizworld I/FA: App measurement is starting up, version: 10298
01-18 23:14:14.144 23773-23773/com.android.appgallery.quizworld I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
01-18 23:14:14.163 23773-23773/com.android.appgallery.quizworld V/FA: Collection enabled
01-18 23:14:14.163 23773-23773/com.android.appgallery.quizworld V/FA: App package, google app id: com.android.appgallery.quizworld,
1:778477946548:android:1b7a8c110537f112
01-18 23:14:14.163 23773-23773/com.android.appgallery.quizworld I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app
com.android.appgallery.quizworld
01-18 23:14:14.163 23773-23773/com.android.appgallery.quizworld D/FA: Debug-level message logging enabled
01-18 23:14:14.210 23773-23773/com.android.appgallery.quizworld V/FA: Registered activity lifecycle callback
01-18 23:14:14.212 23773-23773/com.android.appgallery.quizworld I/FirebaseInitProvider: FirebaseApp initialization successful
01-18 23:14:14.213 23773-23773/com.android.appgallery.quizworld I/InstantRun: starting instant run server: is main process
01-18 23:14:14.219 23773-23792/com.android.appgallery.quizworld V/FA: Using measurement service
01-18 23:14:14.225 23773-23792/com.android.appgallery.quizworld V/FA: Connecting to remote service
01-18 23:14:14.297 23773-23773/com.android.appgallery.quizworld W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter
android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList,
android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
01-18 23:14:14.306 23773-23773/com.android.appgallery.quizworld V/FA: onActivityCreated
01-18 23:14:14.472 23773-23773/com.android.appgallery.quizworld D/AndroidRuntime: Shutting down VM
01-18 23:14:14.473 23773-23773/com.android.appgallery.quizworld E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.appgallery.quizworld, PID: 23773
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.android.appgallery.quizworld/com.android.appgallery.quizworld.MainActivity}: android.view.InflateException: Binary XML file line
#0: Binary XML file line #0: Error inflating class MaterialEditText
at android.app.ActivityThread.performLaunchActivity
(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity
(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage
(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:755)
Caused by: android.view.InflateException: Binary XML file line
#0: Binary XML file line #0: Error inflating class MaterialEditText
at com.android.appgallery.quizworld.MainActivity.onCreate
(MainActivity.java:45)
at android.app.Activity.performCreate(Activity.java:6705)
at android.app.Instrumentation.callActivityOnCreate
(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity
(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity
(ActivityThread.java:2707) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage
(ActivityThread.java:1460) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:865) 
at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:755) 
Caused by: android.view.InflateException: Binary XML file line
#0: Binary XML file line #0: Error inflating class MaterialEditText
Caused by: android.view.InflateException: Binary XML file line
#0: Error inflating class MaterialEditText
Caused by: java.lang.ClassNotFoundException: Didn't find class
"android.view.MaterialEditText" on path: DexPathList[[zip file "/data/app/com.android.appgallery.quizworld-2/base.apk", zip file
"/data/app/com.android.appgallery.quizworld-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-
2/split_lib_slice_0_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-2/split_lib_slice_1_apk.apk", zip file
"/data/app/com.android.appgallery.quizworld-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-
2/split_lib_slice_3_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-2/split_lib_slice_4_apk.apk", zip file
"/data/app/com.android.appgallery.quizworld-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-
2/split_lib_slice_6_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-2/split_lib_slice_7_apk.apk", zip file
"/data/app/com.android.appgallery.quizworld-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-
2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.android.appgallery.quizworld-2/lib/arm, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass
(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView
(LayoutInflater.java:609)
at android.view.LayoutInflater.onCreateView
(LayoutInflater.java:700)
at
com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
at android.view.LayoutInflater.onCreateView
(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag
(LayoutInflater.java:785)
at android.view.LayoutInflater.createViewFromTag
(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate
(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren
(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate
(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren
(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate
(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren
(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate
(LayoutInflater.java:861)
01-18 23:14:14.474 23773-23773/com.android.appgallery.quizworld E/AndroidRuntime: at android.view.LayoutInflater.rInflateChildren
(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate
(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate
(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate
(LayoutInflater.java:377)
at
android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
at android.support.v7.app.AppCompatActivity.setContentView
(AppCompatActivity.java:140)
at com.android.appgallery.quizworld.MainActivity.onCreate
(MainActivity.java:42)
at android.app.Activity.performCreate(Activity.java:6705)
at android.app.Instrumentation.callActivityOnCreate
(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity
(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity
(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage
(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:755)

Physical Device only - Google Maps - 'File.mkdir()' on a null object reference

I am running my code and getting this error when using app on mobile devide, but on emulator it is working.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.nirbhaym.Indoor, PID: 17543
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nirbhaym.Indoor/com.example.nirbhaym.indoor.MapsActivity}: android.view.InflateException: Binary XML file line #62: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2335)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2397)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1310)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5268)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
Caused by: android.view.InflateException: Binary XML file line #62: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.example.nirbhaym.indoor.MapsActivity.onCreate(MapsActivity.java:50)
at android.app.Activity.performCreate(Activity.java:6033)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2397) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1310) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5268) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697) 
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.File.mkdir()' on a null object reference
at com.google.maps.api.android.lib6.gmm6.m.ad.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.c.h.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.c.y.a(Unknown Source)
at com.google.maps.api.android.lib6.e.bd.a(Unknown Source)
at com.google.maps.api.android.lib6.e.ev.a(Unknown Source)
at com.google.maps.api.android.lib6.e.z.a(Unknown Source)
at com.google.maps.api.android.lib6.e.y.a(Unknown Source)
at com.google.android.gms.maps.internal.u.onTransact(SourceFile:107)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.IMapFragmentDelegate$zza$zza.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$zza.onCreateView(Unknown Source)
at com.google.android.gms.dynamic.zza$4.zzb(Unknown Source)
at com.google.android.gms.dynamic.zza.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1036)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1226)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1328)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2284)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:314)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
at com.example.nirbhaym.indoor.MapsActivity.onCreate(MapsActivity.java:50) 
at android.app.Activity.performCreate(Activity.java:6033) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2397) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1310) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5268) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697) 
I/Process: Sending signal. PID: 17543 SIG: 9
Application terminated.
Main activity code
package com.example.nirbhaym.indoor;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.GroundOverlay;
import com.google.android.gms.maps.model.GroundOverlayOptions;
import com.google.android.gms.maps.model.LatLng;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import java.util.ArrayList;
import java.util.List;
/**
* This shows how to add a ground overlay to a map.
*/
public class MapsActivity extends AppCompatActivity
implements OnSeekBarChangeListener, OnMapReadyCallback,
GoogleMap.OnGroundOverlayClickListener {
private static final int TRANSPARENCY_MAX = 100;
private static final LatLng NEWARK = new LatLng(28.544594, 77.272486);
private static final LatLng NEAR_NEWARK =
new LatLng(NEWARK.latitude - 0.001, NEWARK.longitude - 0.025);
private final List<BitmapDescriptor> mImages = new ArrayList<BitmapDescriptor>();
private GroundOverlay mGroundOverlay;
private GroundOverlay mGroundOverlayRotated;
private SeekBar mTransparencyBar;
private int mCurrentEntry = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
mTransparencyBar = (SeekBar) findViewById(R.id.transparencySeekBar);
mTransparencyBar.setMax(TRANSPARENCY_MAX);
mTransparencyBar.setProgress(0);
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
#Override
public void onMapReady(GoogleMap map) {
// Register a listener to respond to clicks on GroundOverlays.
map.setOnGroundOverlayClickListener(this);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(NEWARK, 11));
mImages.clear();
mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.fourth_floor_app));
//mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.newark_prudential_sunny));
// Add a small, rotated overlay that is clickable by default
// (set by the initial state of the checkbox.)
mGroundOverlayRotated = map.addGroundOverlay(new GroundOverlayOptions()
.image(mImages.get(0)).anchor(0, 1)
.position(NEAR_NEWARK, 4300f, 3025f)
.bearing(30)
.clickable(((CheckBox) findViewById(R.id.toggleClickability)).isChecked()));
// Add a large overlay at Newark on top of the smaller overlay.
mGroundOverlay = map.addGroundOverlay(new GroundOverlayOptions()
.image(mImages.get(mCurrentEntry)).anchor(0, 1)
.position(NEWARK, 8600f, 6500f));
mTransparencyBar.setOnSeekBarChangeListener(this);
// Override the default content description on the view, for accessibility mode.
// Ideally this string would be localised.
map.setContentDescription("Google Map with ground overlay.");
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (mGroundOverlay != null) {
mGroundOverlay.setTransparency((float) progress / (float) TRANSPARENCY_MAX);
}
}
public void switchImage(View view) {
mCurrentEntry = (mCurrentEntry + 1) % mImages.size();
mGroundOverlay.setImage(mImages.get(mCurrentEntry));
}
/**
* Toggles the visibility between 100% and 50% when a {#link GroundOverlay} is clicked.
*/
#Override
public void onGroundOverlayClick(GroundOverlay groundOverlay) {
// Toggle transparency value between 0.0f and 0.5f. Initial default value is 0.0f.
mGroundOverlayRotated.setTransparency(0.5f - mGroundOverlayRotated.getTransparency());
}
/**
* Toggles the clickability of the smaller, rotated overlay based on the state of the View that
* triggered this call.
* This callback is defined on the CheckBox in the layout for this Activity.
*/
public void toggleClickability(View view) {
if (mGroundOverlayRotated != null) {
mGroundOverlayRotated.setClickable(((CheckBox) view).isChecked());
}
}
}
Layout file
<?xml version="1.0" encoding="utf-8"?><!--
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/fourth_floor_app"
android:padding="5dp">
<TextView
android:id="#+id/transparency_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="string/transparency" />
<SeekBar
android:id="#+id/transparencySeekBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/transparency_text"
android:layout_toRightOf="#+id/transparency_text" />
<Button
android:id="#+id/switchImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/transparencySeekBar"
android:onClick="switchImage"
android:text="string/switch_image" />
<CheckBox
android:id="#+id/toggleClickability"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/switchImage"
android:layout_toEndOf="#+id/switchImage"
android:layout_toRightOf="#+id/switchImage"
android:checked="true"
android:onClick="toggleClickability"
android:text="string/clickable" />
</RelativeLayout>
<fragment
android:id="#+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
FragmentManager fmanager = getSupportFragmentManager();
Fragment fragment = fmanager.findFragmentById(R.id.map);
SupportMapFragment supportmapfragment = (SupportMapFragment)fragment;
GoogleMap supportMap = supportmapfragment.getMap();
try this code. For this the tutorial is here hope this helps you. The problem is in fragment only. You need to check permissions also in above tutorial. Hope it helps you
http://www.truiton.com/2013/05/android-supportmapfragment-example/
EDIT:
Check permission for External Storage:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Categories