NullPointerException Fehler; App funktioniert nur noch im Emulator

R

rancor26

Neues Mitglied
Threadstarter
Hallo,
ich habe meine erste App programmiert. Dies ging auch sehr gut, ich konnte sie auf einem Handy installieren und stabil laufen lassen.
Nach einen Update von Gradl funktioniert die App nur noch im Emulator aber nicht mehr auf meinem Handy. Es kommt die Fehlermeldung "App wurde beendet" auf dem Handy.
Ich denke es hat etwas mit dem Update zu tun, jedoch sicher bin ich mir nicht.
Hier der Ausszug aus dem Logcat und der Code der den Fehler anscheinend verursacht.

Code:
09-16 08:31:12.514 9243-9243/? I/art: Late-enabling -Xcheck:jni
09-16 08:31:12.614 9243-9243/com.example.bachelor V/Activity: calling onCraete for activity: com.example.bachelor
09-16 08:31:12.674 9243-9243/com.example.bachelor W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.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
09-16 08:31:12.714 9243-9243/com.example.bachelor I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
09-16 08:31:12.724 9243-9243/com.example.bachelor I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
09-16 08:31:12.874 9243-9243/com.example.bachelor D/AndroidRuntime: Shutting down VM
09-16 08:31:12.884 9243-9243/com.example.bachelor E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.bachelor, PID: 9243
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bachelor/com.example.bachelor.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.Bundle.containsKey(java.lang.String)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2348)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2410)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1313)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5345)
        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:947)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.Bundle.containsKey(java.lang.String)' on a null object reference
        at com.example.bachelor.fragment.MineralDetailFragment.onViewCreated(MineralDetailFragment.java:34)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1471)
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
        at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
        at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273)
        at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:620)
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236)
        at android.app.Activity.performStart(Activity.java:6031)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2410) 
        at android.app.ActivityThread.access$800(ActivityThread.java:151) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1313) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5345) 
        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:947) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)
Code:
package com.example.bachelor.fragment;
import android.net.UrlQuerySanitizer;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.fragment.app.Fragment;
import com.example.bachelor.R;
import com.example.bachelor.data.Mineral;
import com.squareup.picasso.Picasso;
import java.net.URL;

public class MineralDetailFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_mineral_detail, null);
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Bundle bundle = getArguments();

        if (bundle.containsKey("mineral")){

            Mineral mineral = (Mineral) bundle.getSerializable("mineral");
            final ImageView mineralImageView = (ImageView) view.findViewById(R.id.imageview_mineral);
            TextView descriptionTextView = (TextView) view.findViewById(R.id.textview_description);
            Picasso.get().load(mineral.getImageUrl()).placeholder(R.drawable.android3).into(mineralImageView);
            descriptionTextView.setText(mineral.getDescription());

        }
        }
    }
Viele Grüße
 
swa00

swa00

Moderator
Teammitglied
Hallo @rancor26,

und willkommen im Forum.

Nun , dein bundle ist zumindest null - das sagt zumindest dein Log .
Das hat aber nichts mit dem Gradle zu tun .


Hat dein Gradle-Target denn auch das richtige Min SDK angegeben ?
 
Zuletzt bearbeitet:
Oben Unten