Home > Software design >  Fatal Exception startactivity in Android studio
Fatal Exception startactivity in Android studio

Time:05-17

I am totally new at Android / Java. and i have some project school and i have this code

```
package com.example.utsmobileprograming;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
    EditText etinput;
    CheckBox ckkotak, cksegitiga;
    Button btkirim;
    //membuat variabel object tipe data Proses

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

        etinput=(EditText) findViewById(R.id.editTextTextInput);
        ckkotak=(CheckBox) findViewById(R.id.checkBoxKotak);
        cksegitiga=(CheckBox) findViewById(R.id.checkBoxSegitiga);
        btkirim=(Button) findViewById(R.id.buttonKirim);

        btkirim.setOnClickListener(v -> {
            Intent intentbentuk = new Intent(getApplicationContext(), ActivityHasil.class);
            intentbentuk.putExtra("inputan", etinput.getText().toString());
            intentbentuk.putExtra("kotak", ckkotak.isChecked());
            intentbentuk.putExtra("segitiga", cksegitiga.isChecked());
            startActivity(intentbentuk);
        });
    }
}

```

but i didn't find my error because i see this the log in my android studio

2022-05-14 03:28:34.002 6525-6525/com.example.utsmobileprograming E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.utsmobileprograming, PID: 6525
    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.utsmobileprograming/com.example.utsmobileprograming.ActivityHasil}; have you declared this activity in your AndroidManifest.xml?
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2065)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1727)
        at android.app.Activity.startActivityForResult(Activity.java:5314)
        at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:597)
        at android.app.Activity.startActivityForResult(Activity.java:5272)
        at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:583)
        at android.app.Activity.startActivity(Activity.java:5658)
        at android.app.Activity.startActivity(Activity.java:5611)
        at com.example.utsmobileprograming.MainActivity.lambda$onCreate$0$com-example-utsmobileprograming-MainActivity(MainActivity.java:32)

how to solve this? is the startActivity my problem ?

CodePudding user response:

You have to add ActivityHasil to your AndroidManifest.xml file like following

<activity android:name="ActivityHasil" android:exported="false"/>
  • Related