У меня следующая проблема, мне нужно накачать только один элемент (выход из системы) до ActionBar
, отображаемого в LoginActivity
.Но это бросает "unexpected EOF!"
.Итак, я пробовал разные способы раздувания элемента, чтобы показать его на панели действий, но все еще без хороших результатов, в конце я поместил сообщение об ошибке.
Это пример изображения (чтопоказывает) элемент не показан ..
Мой код следующий:
app / java / package / MainActivity.
public class MainActivity extends AppCompatActivity {
CircleImageView profile_image;
TextView username;
FirebaseUser firebaseUser;
DatabaseReference reference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar();
profile_image = findViewById(R.id.profile_image);
username = (TextView) findViewById(R.id.userId);
firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
reference = FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
User2 user = dataSnapshot.getValue(User2.class);
System.out.println(user);
Log.d("Userz",user.getUsername());
username.setText(user.getUsername().toString());
if(user.getImageURL().equals("default")){
profile_image.setImageResource(R.mipmap.ic_launcher);
} else {
Glide.with(MainActivity.this).load(user.getImageURL()).into(profile_image);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
//getMenuInflater().inflate(R.menu.menu,menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
Log.d("Itemid",item.toString());
switch(item.getItemId()){
case R.id.logoutItem:
FirebaseAuth.getInstance().signOut();
startActivity(new Intent(MainActivity.this, StartActivity.class));
finish();
return true;
}
return false;
}
}
app /res / menu / menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/logoutItem"
android:title="Logout"
app:showAsAction="always"
/>
</menu>
app / res / layout / activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/MenuStyle">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/profile_image"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/userId"
android:text="username"
android:textColor="#fff"
android:layout_marginLeft="25dp"
android:layout_marginStart="25dp"
android:textStyle="bold"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
</LinearLayout>
Сообщение об ошибке:
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:631)
at android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
at android.support.v7.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:403)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:191)
at com.affinity.affinityteam.firebase_chat_try2.MainActivity.onCreateView(MainActivity.java:40)
at android.app.Activity.onCreateView(Activity.java:6184)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:389)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:631)
at android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
at android.support.v7.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:403)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:191)
at com.affinity.affinityteam.firebase_chat_try2.MainActivity.onCreateView(MainActivity.java:40)
at android.app.Activity.onCreateView(Activity.java:6184)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:389)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:631)
at android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
at android.support.v7.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:403)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:191)
at com.affinity.affinityteam.firebase_chat_try2.MainActivity.onCreateView(MainActivity.java:40)
at android.app.Activity.onCreateView(Activity.java:6184)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:389)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:631)
at android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
at android.support.v7.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:403)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:191)
at com.affinity.affinityteam.firebase_chat_try2.MainActivity.onCreateView(MainActivity.java:40)
at android.app.Activity.onCreateView(Activity.java:6184)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:389)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
read: unexpected EOF!