Support
Quality
Security
License
Reuse
kandi has reviewed VBlog and discovered the below as its top functions. This is intended to give you an instant insight into VBlog implemented functionality, and help decide if they suit your requirements.
V部落,Vue+SpringBoot实现的多用户博客管理平台!
快速运行
git@github.com:lenve/VBlog.git
null-pointer exception of FAB (even though it is defined well) after adding network detection code
if(!isConnected(MainActivity.this)) buildDialog(MainActivity.this).show();
else {
setContentView(R.layout.activity_main);
}
if(!isConnected(MainActivity.this)) buildDialog(MainActivity.this).show();
else {
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","xxxxx@gmail.com", null));
String subject = "Suggest/Feedback -- VB";
String message = "";
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
-----------------------
if(!isConnected(MainActivity.this)) buildDialog(MainActivity.this).show();
else {
setContentView(R.layout.activity_main);
}
if(!isConnected(MainActivity.this)) buildDialog(MainActivity.this).show();
else {
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","xxxxx@gmail.com", null));
String subject = "Suggest/Feedback -- VB";
String message = "";
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
unable to get rid of all emojis
import unicodedata
s = "Wife • Homeschooling Mom to 5 • D Y I lover • Small town living in MN. "
# Just filter category "symbol"
t = ''.join(c for c in s if unicodedata.category(c) not in ('So', ))
print(t)
Wife • Homeschooling Mom to 5 • D Y I lover • Small town living in MN.
# Filter symbols and punctuations. You may want 'Cc' as well,
# to get rid of control characters. Beware that newlines are a
# form of control-character.
t = ''.join(c for c in s if unicodedata.category(c) not in ('So', 'Po'))
print(t)
Wife Homeschooling Mom to 5 D Y I lover Small town living in MN
-----------------------
import unicodedata
s = "Wife • Homeschooling Mom to 5 • D Y I lover • Small town living in MN. "
# Just filter category "symbol"
t = ''.join(c for c in s if unicodedata.category(c) not in ('So', ))
print(t)
Wife • Homeschooling Mom to 5 • D Y I lover • Small town living in MN.
# Filter symbols and punctuations. You may want 'Cc' as well,
# to get rid of control characters. Beware that newlines are a
# form of control-character.
t = ''.join(c for c in s if unicodedata.category(c) not in ('So', 'Po'))
print(t)
Wife Homeschooling Mom to 5 D Y I lover Small town living in MN
-----------------------
import unicodedata
s = "Wife • Homeschooling Mom to 5 • D Y I lover • Small town living in MN. "
# Just filter category "symbol"
t = ''.join(c for c in s if unicodedata.category(c) not in ('So', ))
print(t)
Wife • Homeschooling Mom to 5 • D Y I lover • Small town living in MN.
# Filter symbols and punctuations. You may want 'Cc' as well,
# to get rid of control characters. Beware that newlines are a
# form of control-character.
t = ''.join(c for c in s if unicodedata.category(c) not in ('So', 'Po'))
print(t)
Wife Homeschooling Mom to 5 D Y I lover Small town living in MN
-----------------------
import unicodedata
s = "Wife • Homeschooling Mom to 5 • D Y I lover • Small town living in MN. "
# Just filter category "symbol"
t = ''.join(c for c in s if unicodedata.category(c) not in ('So', ))
print(t)
Wife • Homeschooling Mom to 5 • D Y I lover • Small town living in MN.
# Filter symbols and punctuations. You may want 'Cc' as well,
# to get rid of control characters. Beware that newlines are a
# form of control-character.
t = ''.join(c for c in s if unicodedata.category(c) not in ('So', 'Po'))
print(t)
Wife Homeschooling Mom to 5 D Y I lover Small town living in MN
How to pass the foreign key during the seed in Entity Framework
// Create/Update the roles
context.Roleses.AddOrUpdate(x => x.RoleName,
new Roles { RoleName = "Admin", Weightage = 3 },
new Roles { RoleName = "User", Weightage = 1 }
);
// Ensure the roles are in the database
context.SaveChanges();
// Fetch the "user" role
Roles userRole = context.Roleses.Single(r => r.RoleName == "User");
// Create/Update the user
context.Userses.AddOrUpdate(x=>x.EmailId,
new Users() {
FirstName = "vir",
LastName = "acker",
EmailId = "vir.acker@xyz.com",
Password = password,
Gender = "Male",
Islocked = "false",
CreatedDate = DateTime.Now,
RoleId = userRole.Id
}
);
QUESTION
null-pointer exception of FAB (even though it is defined well) after adding network detection code
Asked 2018-Sep-08 at 20:03I've added some code to detect if there is internet connection or not (please find it below), it goes well, but when i want to show mainactivity only when there is internet connection, the app is throwing fab null-pointer exception. Here is my logcat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.material.manohar.vblogs/com.material.manohar.vblogs.MainActivity}:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.design.widget.FloatingActionButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2779)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2857)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1590)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6499)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.design.widget.FloatingActionButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
MainActivity.java
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(!isConnected(MainActivity.this)) buildDialog(MainActivity.this).show();
else {
setContentView(R.layout.activity_main);
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","xxxxx@gmail.com", null));
String subject = "Suggest/Feedback -- VB";
String message = "";
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
public boolean isConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnectedOrConnecting()) {
android.net.NetworkInfo wifi=cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
android.net.NetworkInfo mobile=cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if ((mobile!= null && mobile.isConnectedOrConnecting()) || (wifi!= null && wifi.isConnectedOrConnecting())) return true;
else return false;
}
else
return false;
}
public AlertDialog.Builder buildDialog(Context c) {
AlertDialog.Builder builder = new AlertDialog.Builder(c);
builder.setTitle("No Internet Connection");
builder.setMessage("You need to have Mobile Data or wifi to access the app. Press ok to Exit");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
return builder;
}
//Rest code is nav drawer functionalities which we get by selecting nav drawer activity layout.
Hare is my activity_main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
The app_bar_main.xml file which contains fab view:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:titleTextAppearance="@style/TitleBarTextAppearance"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
ANSWER
Answered 2018-Sep-08 at 14:12Look carefully at your code, specifically this part:
if(!isConnected(MainActivity.this)) buildDialog(MainActivity.this).show();
else {
setContentView(R.layout.activity_main);
}
You're only calling setContentView()
when you have a connection, but you're initializing and editing Views no matter what. If you don't have internet, your if statement will run buildDialog().show()
, _and then continue onto the rest of your onCreate()
.
To solve this, just put everything else in onCreate()
under setContentView()
in your else block:
if(!isConnected(MainActivity.this)) buildDialog(MainActivity.this).show();
else {
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","xxxxx@gmail.com", null));
String subject = "Suggest/Feedback -- VB";
String message = "";
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit