dizzy'
dizzy'

Reputation: 1

Error trying to start new activity on Android app

My LOG CAT

2021-05-26 19:04:51.813 25933-25933/com.melikerdemkoc.myvetapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.melikerdemkoc.myvetapp, PID: 25933
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.melikerdemkoc.myvetapp/com.melikerdemkoc.myvetapp.Kayit_ol_acticvity}: java.lang.IllegalAccessException: java.lang.Class<com.melikerdemkoc.myvetapp.Kayit_ol_acticvity> is not accessible from java.lang.Class<android.app.AppComponentFactory>
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3365)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.IllegalAccessException: java.lang.Class<com.melikerdemkoc.myvetapp.Kayit_ol_acticvity> is not accessible from java.lang.Class<android.app.AppComponentFactory>
        at java.lang.Class.newInstance(Native Method)
        at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
        at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1253)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3353)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7656) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)**

This is my logcat error I wanna switch between pages but I can't do this. Below you can find the code



package com.melikerdemkoc.myvetapp;

import androidx.appcompat.app.AppCompatActivity;

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

import com.melikerdemkoc.myvetapp.R;

public class MainActivity extends AppCompatActivity {

    Button btnNext;
    Context context = this;

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

        btnNext = findViewById(R.id.kayıtol);



        btnNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //Intent ıntent = new Intent(MainActivity.this, SecondActivity.class);
                Intent ıntent = new Intent(context, Kayit_ol_acticvity.class);

                startActivity(ıntent);
            }
        });
    }
}

    
    package com.melikerdemkoc.myvetapp;
    
    import android.os.Bundle;
    
    import androidx.annotation.Nullable;
    import androidx.appcompat.app.AppCompatActivity;
    
    class Kayit_ol_acticvity extends AppCompatActivity {
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.kayit_ol);
        }
    }

I'm getting lines like this in my code, unfortunately, I haven't found a solution, I would appreciate it if you could help me! Thanks in advance!

In this code, my purpose was to direct you to the signup page when you click REGISTER. **Intent is so important pls send codes for my project if you do this ım so happy thank you ı need this

Upvotes: 0

Views: 2671

Answers (2)

AShX
AShX

Reputation: 412

class Kayit_ol_acticvity should be public
Try this :

public class Kayit_ol_acticvity extends AppCompatActivity {...
}

Documentation -Controlling Access to Members of a Class :

A class may be declared with the modifier public, in which case that class is visible to all classes everywhere. If a class has no modifier (the default, also known as package-private), it is visible only within its own package (packages are named groups of related classes)

P.S. It's good tone to use UpperCamelCase for naming classes and avoid _, so in yours case it's KayitOlActicvity

Upvotes: 0

dominicoder
dominicoder

Reputation: 10155

Your error says the class is not accessible.

You've defined the class like this:

class Kayit_ol_acticvity extends AppCompatActivity {

In Java, if you don't specify the type of access on a class, it default to package which means it's only accessible to the other code in the same package. It needs to be public for Android classes to access it.

Change your code to this:

public class Kayit_ol_acticvity extends AppCompatActivity {

Upvotes: 1

Related Questions