#java #android
#java #Android
Вопрос:
Всякий раз, когда я пытаюсь войти / зарегистрироваться в своем приложении, устройство перезагружается, и я получаю много ошибок в logcat, но я не понимаю, что это значит. Я также видел кое-что о HomeFragment.java
файле в ошибках, но я удалил этот файл 3 дня назад, и он больше не существует в папке моего проекта.
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sm.socialmeme">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/app_logo"
android:label="@string/app_name"
android:roundIcon="@drawable/app_logo"
android:supportsRtl="true"
android:theme="@style/Theme.SocialMeme">
<activity android:name=".UploadPhotoActivity"/>
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings" />
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HomeActivity" />
<activity android:name=".SignupActivity" />
<activity android:name=".MainActivity" />
</application>
</manifest>
Вот некоторые ошибки из logcat:
2021-02-21 13:51:07.033 28769-28769/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sm.socialmeme, PID: 28769
java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.fragment.app.FragmentManager androidx.fragment.app.FragmentActivity.getSupportFragmentManager()' on a null object reference
at com.sm.socialmeme.HomeFragment$2.onNavigationItemSelected(HomeFragment.java:132)
at com.google.android.material.bottomnavigation.BottomNavigationView$1.onMenuItemSelected(BottomNavigationView.java:241)
at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:834)
at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:985)
at com.google.android.material.bottomnavigation.BottomNavigationMenuView$1.onClick(BottomNavigationMenuView.java:131)
at android.view.View.performClick(View.java:7862)
at android.view.View.performClickInternal(View.java:7831)
at android.view.View.access$3600(View.java:879)
at android.view.View$PerformClick.run(View.java:29359)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2021-02-21 13:51:19.320 31157-31157/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sm.socialmeme, PID: 31157
java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.fragment.app.FragmentManager androidx.fragment.app.FragmentActivity.getSupportFragmentManager()' on a null object reference
at com.sm.socialmeme.HomeFragment$2.onNavigationItemSelected(HomeFragment.java:132)
at com.google.android.material.bottomnavigation.BottomNavigationView$1.onMenuItemSelected(BottomNavigationView.java:241)
at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:834)
at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:985)
at com.google.android.material.bottomnavigation.BottomNavigationMenuView$1.onClick(BottomNavigationMenuView.java:131)
at android.view.View.performClick(View.java:7862)
at android.view.View.performClickInternal(View.java:7831)
at android.view.View.access$3600(View.java:879)
at android.view.View$PerformClick.run(View.java:29359)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2021-02-21 13:52:03.540 31590-31590/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sm.socialmeme, PID: 31590
java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.fragment.app.FragmentManager androidx.fragment.app.FragmentActivity.getSupportFragmentManager()' on a null object reference
at com.sm.socialmeme.HomeFragment$2.onNavigationItemSelected(HomeFragment.java:132)
at com.google.android.material.bottomnavigation.BottomNavigationView$1.onMenuItemSelected(BottomNavigationView.java:241)
at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:834)
at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:985)
at com.google.android.material.bottomnavigation.BottomNavigationMenuView$1.onClick(BottomNavigationMenuView.java:131)
at android.view.View.performClick(View.java:7862)
at android.view.View.performClickInternal(View.java:7831)
at android.view.View.access$3600(View.java:879)
at android.view.View$PerformClick.run(View.java:29359)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2021-02-21 13:54:33.531 28735-28735/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sm.socialmeme, PID: 28735
java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.fragment.app.FragmentManager androidx.fragment.app.FragmentActivity.getSupportFragmentManager()' on a null object reference
at com.sm.socialmeme.HomeFragment$2.onNavigationItemSelected(HomeFragment.java:132)
at com.google.android.material.bottomnavigation.BottomNavigationView$1.onMenuItemSelected(BottomNavigationView.java:241)
at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:834)
at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:985)
at com.google.android.material.bottomnavigation.BottomNavigationMenuView$1.onClick(BottomNavigationMenuView.java:131)
at android.view.View.performClick(View.java:7862)
at android.view.View.performClickInternal(View.java:7831)
at android.view.View.access$3600(View.java:879)
at android.view.View$PerformClick.run(View.java:29359)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2021-02-21 14:01:03.009 5676-5676/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sm.socialmeme, PID: 5676
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.sm.socialmeme/com.sm.socialmeme.HomeFragment}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2074)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1720)
at android.app.Activity.startActivityForResult(Activity.java:5258)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:675)
at android.app.Activity.startActivityForResult(Activity.java:5203)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:662)
at android.app.Activity.startActivity(Activity.java:5587)
at android.app.Activity.startActivity(Activity.java:5555)
at com.sm.socialmeme.SplashActivity$1.run(SplashActivity.java:51)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2021-02-21 14:02:17.396 9124-9124/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sm.socialmeme, PID: 9124
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.sm.socialmeme/com.sm.socialmeme.HomeFragment}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2074)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1720)
at android.app.Activity.startActivityForResult(Activity.java:5258)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:675)
at android.app.Activity.startActivityForResult(Activity.java:5203)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:662)
at android.app.Activity.startActivity(Activity.java:5587)
at android.app.Activity.startActivity(Activity.java:5555)
at com.sm.socialmeme.SplashActivity$1.run(SplashActivity.java:51)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2021-02-23 19:19:46.264 7625-7642/? E/AndroidRuntime: !@*** FATAL EXCEPTION IN SYSTEM PROCESS: android.ui
java.lang.RuntimeException: Canvas: trying to draw too large(173501584bytes) bitmap.
at android.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:281)
at android.graphics.BaseRecordingCanvas.drawBitmap(BaseRecordingCanvas.java:91)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:548)
at android.widget.ImageView.onDraw(ImageView.java:1434)
at android.view.View.draw(View.java:23187)
at android.view.View.updateDisplayListIfDirty(View.java:22062)
at android.view.View.draw(View.java:22917)
at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
at android.view.View.draw(View.java:23190)
at android.view.View.updateDisplayListIfDirty(View.java:22062)
at android.view.View.draw(View.java:22917)
at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
at android.view.View.draw(View.java:23190)
at android.view.View.updateDisplayListIfDirty(View.java:22062)
at android.view.View.draw(View.java:22917)
at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
at android.widget.ListView.drawChild(ListView.java:3841)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
at android.widget.AbsListView.dispatchDraw(AbsListView.java:3594)
at android.widget.ListView.dispatchDraw(ListView.java:3821)
at android.view.View.draw(View.java:23190)
at android.widget.AbsListView.draw(AbsListView.java:7190)
at android.view.View.updateDisplayListIfDirty(View.java:22062)
at android.view.View.draw(View.java:22917)
at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
at android.view.View.updateDisplayListIfDirty(View.java:22048)
at android.view.View.draw(View.java:22917)
at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
at android.view.View.draw(View.java:23190)
at android.view.View.updateDisplayListIfDirty(View.java:22062)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:588)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:594)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:667)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:4296)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:4080)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3348)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2225)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9126)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:999)
at android.view.Choreographer.doCallbacks(Choreographer.java:797)
at android.view.Choreographer.doFrame(Choreographer.java:732)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:984)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.os.HandlerThread.run(HandlerThread.java:67)
at com.android.server.ServiceThread.run(ServiceThread.java:44)
at com.android.server.UiThread.run(UiThread.java:43)
MainActivity.java:
package com.sm.socialmeme;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.auth.AuthResu<
import com.google.firebase.auth.FirebaseAuth;
import org.jetbrains.annotations.NotNull;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FirebaseAuth mAuth;
mAuth = FirebaseAuth.getInstance();
final EditText username = findViewById(R.id.username);
final EditText password = findViewById(R.id.password);
final Button login_btn = findViewById(R.id.login_btn);
final ProgressBar loading_bar = findViewById(R.id.progressBar);
final TextView signup = findViewById(R.id.textView4);
loading_bar.setVisibility(View.GONE);
signup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this,SignupActivity.class));
}
});
login_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loading_bar.setVisibility(View.VISIBLE);
final String email_input = username.getText().toString();
final String password_input = password.getText().toString();
if (email_input.isEmpty() || password_input.isEmpty()){
loading_bar.setVisibility(View.GONE);
Toast.makeText(MainActivity.this, "All values are required", Toast.LENGTH_LONG).show();
}else{
mAuth.signInWithEmailAndPassword(email_input,password_input).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull @NotNull Task<AuthResult> task) {
if (task.isSuccessful()){
finish();
startActivity(new Intent(MainActivity.this, HomeActivity.class));
}else{
loading_bar.setVisibility(View.GONE);
WrongInformationDialog dialog = new WrongInformationDialog();
dialog.show(getSupportFragmentManager(), "dialog");
}
}
});
}
}
});
}
}
HomeActivity.java:
package com.sm.socialmeme;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.os.Bundle;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
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 org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class HomeActivity extends AppCompatActivity {
DatabaseReference postsRef;
DatabaseReference rootRef;
List<PostModel> postList;
RecyclerView.Adapter recyclerAdapter;
RecyclerView recyclerView;
ProgressBar progressBar;
ImageButton like_btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
final FirebaseAuth mAuth = FirebaseAuth.getInstance();
final FirebaseUser user = mAuth.getCurrentUser();
final BottomNavigationView bottomNavBar = findViewById(R.id.bottom_nav);
like_btn = findViewById(R.id.likeBtn);
recyclerView = findViewById(R.id.recyclerView);
postsRef = FirebaseDatabase.getInstance().getReference().child("posts");
rootRef = FirebaseDatabase.getInstance().getReference();
progressBar = findViewById(R.id.progressBar4);
progressBar.setVisibility(View.VISIBLE);
postList = new ArrayList<>();
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setReverseLayout(true);
layoutManager.setStackFromEnd(true);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(layoutManager);
bottomNavBar.setOnNavigationItemSelectedListener(navListener);
// keep selected fragment when rotating device \
/*
if (savedInstanceState == null){
getSupportFragmentManager().beginTransaction().replace(R.id.root_container, new Fragment()).commit();
}*/
if (user == null) {
finish();
startActivity(new Intent(HomeActivity.this, MainActivity.class));
}
postsRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
PostModel post = new PostModel();
post.setImgUrl(snapshot.child("imgUrl").getValue().toString());
post.setName(snapshot.child("name").getValue().toString());
post.setLikes(snapshot.child("likes").getValue().toString());
post.setId(snapshot.child("id").getValue().toString());
postList.add(post);
// notify adapter when a new item was added \
if (recyclerAdapter != null) {
recyclerAdapter.notifyDataSetChanged();
}
}
progressBar.setVisibility(View.INVISIBLE);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(HomeActivity.this, "Error: " databaseError, Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.INVISIBLE);
}
});
recyclerAdapter = new RecyclerAdapter(HomeActivity.this, postList);
recyclerView.setAdapter(recyclerAdapter);
recyclerAdapter.notifyDataSetChanged();
}
private BottomNavigationView.OnNavigationItemSelectedListener navListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@androidx.annotation.NonNull @NotNull MenuItem menuItem) {
//androidx.fragment.app.Fragment selectedFragment = null;
switch (menuItem.getItemId()){
case R.id.home_fragment:
//selectedFragment = new HomeFragment();
//startActivity(new Intent(HomeActivity.this, HomeActivity.class));
break;
case R.id.new_post_fragment:
//selectedFragment = new NewPostFragment();
startActivity(new Intent(getApplicationContext(), UploadPhotoActivity.class));
overridePendingTransition(0,0);
break;
case R.id.settings_fragment:
//selectedFragment = new SettingsFragment();
startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
overridePendingTransition(0,0);
break;
}
return true;
}
};
}
Комментарии:
1. Не могли бы вы опубликовать «Android Manifest.xml «код? Похоже, проблема в этом.
2. @Kidus я добавил это
Ответ №1:
Все ошибки вашего logcat не имеют никакого отношения к вашей проблеме, потому что они происходят 21 февраля, за исключением последней ошибки, в которой появляется только 5 слов, можете ли вы показать мне последнее сообщение об ошибке, которое начинается с
E/AndroidRuntime: !@*** FATAL EXCEPTION IN SYSTEM PROCESS: android.ui
Редактировать
post.setImgUrl(snapshot.child("imgUrl").getValue().toString());
logcat сообщает, что вы пытаетесь нарисовать очень большое растровое изображение, что приводит к вашей проблеме, пожалуйста, попробуйте прокомментировать эту строку в своем коде и попробуйте запустить ее снова.
Комментарии:
1. я добавил это, пожалуйста, помогите мне, если вы обнаружите проблему
2. Я обновляю его, пожалуйста, прокомментируйте его или попробуйте другое маленькое изображение.
3. Если я сделаю это, я получу
nullPointerException
, потому что URL-адрес изображения в модели будет нулевым, а также мое приложение является социальной сетью, и мне нужно загрузить много фотографий. Я попробую это и оставлю здесь еще один комментарий.4. затем я предлагаю протестировать его с любым небольшим изображением, или, если вы используете picasso или glide, вы можете изменить его размер.
5. Я пробую это, и снова у меня та же проблема
Ответ №2:
Измените значение inputType
с textPersonName
на text