hmkcode / Android

Android related examples
3.51k stars 3.41k forks source link

FATAL EXCEPTION: main #145

Closed beturaja closed 8 months ago

beturaja commented 8 months ago

I am creating another app but the following error is occurring:

2023-11-13 20:46:10.288 20988-20988 AndroidRuntime          com.education.quizie                 D  Shutting down VM
2023-11-13 20:46:10.289 20988-20988 AndroidRuntime          com.education.quizie                 E  FATAL EXCEPTION: main
                                                                                                    Process: com.education.quizie, PID: 20988
                                                                                                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.education.quizie/com.education.quizie.MainActivity}: java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup
                                                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3426)
                                                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3575)
                                                                                                        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
                                                                                                        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:137)
                                                                                                        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2131)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:107)
                                                                                                        at android.os.Looper.loop(Looper.java:214)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:7554)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
                                                                                                    Caused by: java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup
                                                                                                        at android.view.ViewGroup.addView(ViewGroup.java:4930)
                                                                                                        at android.view.ViewGroup.addView(ViewGroup.java:4912)
                                                                                                        at com.education.quizie.MainActivity.onCreate(MainActivity.java:168)
                                                                                                        at android.app.Activity.performCreate(Activity.java:7815)
                                                                                                        at android.app.Activity.performCreate(Activity.java:7804)
                                                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1308)
                                                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3401)
                                                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3575) 
                                                                                                        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
                                                                                                        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:137) 
                                                                                                        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) 
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2131) 
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:107) 
                                                                                                        at android.os.Looper.loop(Looper.java:214) 
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:7554) 
                                                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980) 
2023-11-13 20:46:10.345 20988-20988 Process                 com.education.quizie                 I  Sending signal. PID: 20988 SIG: 9
---------------------------- PROCESS ENDED (20988) for package com.education.quizie ----------------------------
2023-11-13 20:46:10.243 20988-20988 ducation.quizi          com.education.quizie                 W  Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2023-11-13 20:46:10.244 20988-20988 ducation.quizi          com.education.quizie                 W  Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2023-11-13 20:46:10.288 20988-20988 AndroidRuntime          com.education.quizie                 D  Shutting down VM
2023-11-13 20:46:10.289 20988-20988 AndroidRuntime          com.education.quizie                 E  FATAL EXCEPTION: main
                                                                                                    Process: com.education.quizie, PID: 20988
                                                                                                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.education.quizie/com.education.quizie.MainActivity}: java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup
                                                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3426)
                                                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3575)
                                                                                                        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
                                                                                                        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:137)
                                                                                                        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2131)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:107)
                                                                                                        at android.os.Looper.loop(Looper.java:214)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:7554)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
                                                                                                    Caused by: java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup
                                                                                                        at android.view.ViewGroup.addView(ViewGroup.java:4930)
                                                                                                        at android.view.ViewGroup.addView(ViewGroup.java:4912)
                                                                                                        at com.education.quizie.MainActivity.onCreate(MainActivity.java:168)
                                                                                                        at android.app.Activity.performCreate(Activity.java:7815)
                                                                                                        at android.app.Activity.performCreate(Activity.java:7804)
                                                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1308)
                                                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3401)
                                                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3575) 
                                                                                                        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
                                                                                                        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:137) 
                                                                                                        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) 
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2131) 
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:107) 
                                                                                                        at android.os.Looper.loop(Looper.java:214) 
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:7554) 
                                                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980) 
2023-11-13 20:46:10.345 20988-20988 Process                 com.education.quizie                 I  Sending signal. PID: 20988 SIG: 9

My code:

package com.education.quizie;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.ViewSwitcher;

import java.io.File;

public class MainActivity extends AppCompatActivity {

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        try {
            if (!(new File("Progress.data").exists())) {
                new File("Progress.data").createNewFile();
                JaScri.writeFile("Progress.data", "UTF-8", "MDA=");
            }
            if (!(new File("btn").exists())) {
                new File("btn").createNewFile();
                JaScri.writeFile("btn", "UTF-8", "dHJ1ZQ==");
            }
            if (!(new File("btn2").exists())) {
                new File("btn2").createNewFile();
                JaScri.writeFile("btn2", "UTF-8", "dHJ1ZQ==");
            }
            if (!(new File("btn3").exists())) {
                new File("btn3").createNewFile();
                JaScri.writeFile("btn3", "UTF-8", "dHJ1ZQ==");
            }
            if (!(new File("btn4").exists())) {
                new File("btn4").createNewFile();
                JaScri.writeFile("btn4", "UTF-8", "dHJ1ZQ==");
            }
            if (!(new File("btn5").exists())) {
                new File("btn5").createNewFile();
                JaScri.writeFile("btn5", "UTF-8", "dHJ1ZQ==");
            }
            if (!(new File("GK").exists())) {
                new File("GK").createNewFile();
                JaScri.writeFile("GK", "UTF-8", "What is the capital of Australia?\n" +
                        "Who wrote the novel \"Pride and Prejudice\"?\n" +
                        "What is the chemical symbol for gold?\n" +
                        "Who painted the Mona Lisa?\n" +
                        "What is the currency of Japan?");
            }
            if (!(new File("GK-A").exists())) {
                new File("GK-A").createNewFile();
                JaScri.writeFile("GK-A", "UTF-8", "Canberra\n" +
                        "Jane Austen\n" +
                        "Au\n" +
                        "Leonardo da Vinci\n" +
                        "Japanese Yen (JPY)");
            }
            if (!(new File("GK-I").exists())) {
                new File("GK-I").createNewFile();
                JaScri.writeFile("GK-I", "UTF-8", "Sydney\n" +
                        "John Steinbeck\n" +
                        "Go\n" +
                        " Vincent Van Gogh\n" +
                        "Japanese Yan (JPY)");
            }
            if (!(new File("Imp").exists())) {
                new File("Imp").createNewFile();
                JaScri.writeFile("Imp", "UTF-8", "What is consciousness?\n" +
                        "Is there a pattern in numbers?\n" +
                        "Can problems be solved as fast as they're checked?\n" +
                        "How do fluids behave?\n" +
                        "Can all forces be in one theory?");
            }
            if (!(new File("Imp-A").exists())) {
                new File("Imp-A").createNewFile();
                JaScri.writeFile("Imp-A", "UTF-8", "Brain's mystery.\n" +
                        "Uncovered regularities.\n" +
                        "Faster solutions?\n" +
                        "Liquid & gas motion.\n" +
                        "Single universal theory.");
            }
            if (!(new File("Imp-I").exists())) {
                new File("Imp-I").createNewFile();
                JaScri.writeFile("Imp-I", "UTF-8", "Brain's part.\n" +
                        "Yes\n" +
                        "Slower solutions\n" +
                        "no motion.\n" +
                        "No");
            }
            if (!(new File("IT").exists())) {
                new File("IT").createNewFile();
                JaScri.writeFile("IT", "UTF-8", "DDoS protection.\n" +
                        "Server virtualization benefits.\n" +
                        "Encryption types in cybersecurity.\n" +
                        "SQL injection risks.\n" +
                        "Cloud computing and migration factors.");
            }
            if (!(new File("IT-A").exists())) {
                new File("IT-A").createNewFile();
                JaScri.writeFile("IT-A", "UTF-8", "Defense against attacks.\n" +
                        "IT advantages.\n" +
                        "Symmetric and asymmetric methods.\n" +
                        "Security risk.\n" +
                        "Business benefits and migration.");
            }
            if (!(new File("IT-I").exists())) {
                new File("IT-I").createNewFile();
                JaScri.writeFile("IT-I", "UTF-8", "Not manage packages\n" +
                        "faster processing\n" +
                        "Symmetric method.\n" +
                        "Computer Breach.\n" +
                        "Business benefits and performance.");
            }
            if (!(new File("Math").exists())) {
                new File("Math").createNewFile();
                JaScri.writeFile("Math", "UTF-8", "Solve for x: 3x^2 - 5x + 2 = 0\n" +
                        "Simplify: (2x^3y^4)(-3x^2y^2)\n" +
                        "Factor the expression: 3x^2 - 12x\n" +
                        "Solve for x and y: 2x + 3y = 11; 4x - 5y = 1\n" +
                        "Find the x value: |2x - 7| = 9?");
            }
            if (!(new File("Math-A").exists())) {
                new File("Math-A").createNewFile();
                JaScri.writeFile("Math-A", "UTF-8", "x = 1 and x = 2/3\n" +
                        "-6x^5y^6\n" +
                        "3x(x - 4)\n" +
                        "x = 3, y = 2\n" +
                        "x = 8 & x = -1");
            }
            if (!(new File("Math-I").exists())) {
                new File("Math-I").createNewFile();
                JaScri.writeFile("Math-I", "UTF-8", "x = 1\n" +
                        "6x^5y^6\n" +
                        "3x(x - 3)\n" +
                        "x = 3, y = 4\n" +
                        "x = 8 & x = 1");
            }
            if (!(new File("Science").exists())) {
                new File("Science").createNewFile();
                JaScri.writeFile("Science", "UTF-8", "What is the Heisenberg Uncertainty Principle?\n" +
                        "Explain exothermic and endothermic reactions.\n" +
                        "Define gene splicing in genetic engineering.\n" +
                        "Describe black holes.\n" +
                        "Explain plate tectonics.");
            }
            if (!(new File("Science-A").exists())) {
                new File("Science-A").createNewFile();
                JaScri.writeFile("Science-A", "UTF-8", "Uncertainty in particle position and momentum.\n" +
                        "Exothermic (heat out), endothermic (heat in).\n" +
                        "Alters traits with DNA mixing.\n" +
                        "Super-gravity traps all, including light.\n" +
                        "Plates move, shape land, shake, uplift mountains.");
            }
            if (!(new File("Science-I").exists())) {
                new File("Science-I").createNewFile();
                JaScri.writeFile("Science-I", "UTF-8", "Uncertainty in particle speed and momentum.\n" +
                        "Exothermic (cool out), endothermic (heat in).\n" +
                        "DNA mixing.\n" +
                        "Super-gravity traps all, but light.\n" +
                        "Plates move, shape land, uplift mountains.");
            }
        } catch (Exception e) {
            //Do nothing
        }
        ViewSwitcher v = (ViewSwitcher) findViewById(R.id.views);
        v.addView(findViewById(R.id.main));
    }
}

&

package com.education.quizie;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;

public class QuizieMain extends AppCompatActivity {
    public static int score;
    public static String[][] questions = new String[5][5];
    public static String[][] answers = new String[5][5];
    public static String[][] inanswers = new String[5][5];
    public static int[][] seq = {{1, 0, 1, 1, 0}, {0, 1, 1, 0, 0}, {1, 0, 0, 0, 1}, {0, 1, 1, 0, 1}, {1, 1, 0, 1, 0}};
    int i = 0;
    public static int[] marks = {10, 10, 10, 10, 60};
    public static int qi = 0;

    {
        try {
            score = Integer.parseInt(JaScri.base64("decode", JaScri.readFile("./Progress.data")));
        } catch (FileNotFoundException | ConversionTypeNotFound | UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_quizie_main);

        Button gk = (Button) findViewById(R.id.button);
        Button math = (Button) findViewById(R.id.button2);
        Button science = (Button) findViewById(R.id.button3);
        Button it = (Button) findViewById(R.id.button4);
        Button adv = (Button) findViewById(R.id.button5);

        TextView ScoreView = (TextView) findViewById(R.id.textView3);

        try {
            gk.setEnabled(Boolean.parseBoolean(JaScri.base64("decode", JaScri.readFile("btn"))));
            math.setEnabled(Boolean.parseBoolean(JaScri.base64("decode", JaScri.readFile("btn2"))));
            science.setEnabled(Boolean.parseBoolean(JaScri.base64("decode", JaScri.readFile("bn3"))));
            it.setEnabled(Boolean.parseBoolean(JaScri.base64("decode", JaScri.readFile("btn4"))));
            adv.setEnabled(Boolean.parseBoolean(JaScri.base64("decode", JaScri.readFile("btn5"))));
        } catch (ConversionTypeNotFound | UnsupportedEncodingException | FileNotFoundException e) {
            throw new RuntimeException(e);
        }

        gk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startQuiz(0);
            }
        });
        math.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startQuiz(1);
            }
        });
        science.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startQuiz(2);
            }
        });
        it.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startQuiz(3);
            }
        });
        adv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startQuiz(4);
            }
        });

        Save();

        File file = new File("GK.txt");
        Scanner reader;
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        StringBuilder content = new StringBuilder();
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            content.append(data).append("\n");
            questions[0][i] = data;
            i++;
        }
        i = 0;
        file = new File("Math.txt");
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            content.append(data).append("\n");
            questions[1][i] = data;
            i++;
        }
        i = 0;
        file = new File("Science.txt");
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            content.append(data).append("\n");
            questions[2][i] = data;
            i++;
        }
        i = 0;
        file = new File("IT.txt");
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            questions[3][i] = data;
            i++;
        }
        i = 0;
        file = new File("Imp.txt");
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            questions[4][i] = data;
            i++;
        }

        i = 0;
        file = new File("GK-A.txt");
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        content = new StringBuilder();
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            content.append(data).append("\n");
            answers[0][i] = data;
            i++;
        }
        i = 0;
        file = new File("Math-A.txt");
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            content.append(data).append("\n");
            answers[1][i] = data;
            i++;
        }
        i = 0;
        file = new File("Science-A.txt");
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            content.append(data).append("\n");
            answers[2][i] = data;
            i++;
        }
        i = 0;
        file = new File("IT-A.txt");
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            answers[3][i] = data;
            i++;
        }
        i = 0;
        file = new File("Imp-A.txt");
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            answers[4][i] = data;
            i++;
        }

        i = 0;
        file = new File("GK-A.txt");
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        content = new StringBuilder();
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            content.append(data).append("\n");
            inanswers[0][i] = data;
            i++;
        }
        i = 0;
        file = new File("Math-A.txt");
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            content.append(data).append("\n");
            inanswers[1][i] = data;
            i++;
        }
        i = 0;
        file = new File("Science-A.txt");
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            content.append(data).append("\n");
            inanswers[2][i] = data;
            i++;
        }
        i = 0;
        file = new File("IT-A.txt");
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            inanswers[3][i] = data;
            i++;
        }
        i = 0;
        file = new File("Imp-A.txt");
        try {
            reader = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        while (reader.hasNextLine()) {
            String data = reader.nextLine();
            inanswers[4][i] = data;
            i++;
        }
        reader.close();

        ScoreView.setText("Score: " + score);
    }

    public void Save() {
        try {
            JaScri.writeFile("Progress.data", "UTF-8", JaScri.base64("encode", "00"));
        } catch (FileNotFoundException | UnsupportedEncodingException | ConversionTypeNotFound e) {
            throw new RuntimeException(e);
        }
    }

    public void startQuiz(int index) {
        qi = index;
        Intent intent = new Intent(QuizieMain.this, QuiziePage.class);
        startActivity(intent);
        setContentView(R.layout.activity_quizie_page);
    }
}

Please help. Thank you