Wince
Wince

Reputation: 129

Activity error even thought its declared in manifest

firsly i want to say i use the 2 Intents i refer in each to change activity between them and i can also move to this class with an intent but when i try to startactivty from this class it crashes .

this is the class where i get the error.

    package com.example.wince.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import java.util.ArrayList;

/**
 * Created by Wince on 31.05.2016.
 */
public class RotaGoster extends FragmentActivity implements OnMapReadyCallback {
    private GoogleMap mMap;
    final Intent rotaIntent = new Intent(this, com.example.wince.myapplication.Rota.class);
    final Intent kayitIntent = new Intent(this, com.example.wince.myapplication.RotaKayit.class);

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.rota);
        String isim = getIntent().getExtras().getString("DB_name");
        VeriTabani VT = new VeriTabani(this);
        Button Kayit = (Button) findViewById(R.id.button6);
        Button Rota = (Button) findViewById(R.id.button7);
        int i = 0;
        ArrayList<Yer> yerler = new ArrayList<>();
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map2);
        mapFragment.getMapAsync(this);
        yerler.addAll(VT.getAllYer());
        for (i = 0; i < yerler.size(); i++) {
            if (yerler.get(i).equals(isim)) {
                mMap.addMarker(new MarkerOptions().position(new LatLng(VT.getYer(i).getLat(), VT.getYer(i).getLng())).title(i + "'inci nokta"));
            }

        }

        Kayit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(kayitIntent);
                finish();
            }
        });

        Rota.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(rotaIntent);
                finish();
            }
        });


        //dbden verileri çekmek gerek


        // db işlemleri ve gösterim burda yapılıcak.


    }

    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);

    }
}

this is the android manifest.xml file

<?xml version="1.0" encoding="utf-8"?>

<!--
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
     Google Maps Android API v2, but you must specify either coarse or fine
     location permissions for the 'MyLocation' functionality. 
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <!--
         The API key for Google Maps-based APIs is defined as a string resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key used to sign the APK.
         You need a different API key for each encryption key, including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release targets in src/debug/ and src/release/. 
    -->
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name=".RotaKayit"
        android:label="@string/title_activity_maps">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Rota"></activity>
    <activity android:name=".RotaGoster"></activity>
</application>

this is the logcat for error

06-05 15:51:55.032 10275-10275/com.example.wince.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
                                                                             Process: com.example.wince.myapplication, PID: 10275
                                                                             android.content.ActivityNotFoundException: Unable to find explicit activity class {/com.example.wince.myapplication.Rota}; have you declared this activity in your AndroidManifest.xml?
                                                                                 at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1636)
                                                                                 at android.app.Instrumentation.execStartActivity(Instrumentation.java:1430)
                                                                                 at android.app.Activity.startActivityForResult(Activity.java:3532)
                                                                                 at android.app.Activity.startActivityForResult(Activity.java:3493)
                                                                                 at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:842)
                                                                                 at android.app.Activity.startActivity(Activity.java:3735)
                                                                                 at android.app.Activity.startActivity(Activity.java:3703)
                                                                                 at com.example.wince.myapplication.RotaGoster$2.onClick(RotaGoster.java:55)
                                                                                 at android.view.View.performClick(View.java:4633)
                                                                                 at android.view.View$PerformClick.run(View.java:19274)
                                                                                 at android.os.Handler.handleCallback(Handler.java:733)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                 at android.os.Looper.loop(Looper.java:146)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5593)
                                                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                 at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
                                                                                 at dalvik.system.NativeStart.main(Native Method)

Upvotes: 0

Views: 42

Answers (2)

OneCricketeer
OneCricketeer

Reputation: 191681

You have a reference to this outside of the instance, so you can only declare the Intents as fields, but you must initialize them in onCreate or later.

They also don't need to be final.

Upvotes: 0

Wince
Wince

Reputation: 129

changing the code like this ; putting intent declarations in the oncreate method seems to solve the problem

    package com.example.wince.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import java.util.ArrayList;

/**
 * Created by Wince on 31.05.2016.
 */
public class RotaGoster extends FragmentActivity implements OnMapReadyCallback {
    private GoogleMap mMap;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.rota);
        String isim = getIntent().getExtras().getString("DB_name");
        VeriTabani VT = new VeriTabani(this);
        Button Kayit = (Button) findViewById(R.id.button6);
        Button Rota = (Button) findViewById(R.id.button7);
        int i = 0;
        final Intent rotaIntent = new Intent(this, Rota.class);
        final Intent kayitIntent = new Intent(this, RotaKayit.class);
        ArrayList<Yer> yerler = new ArrayList<>();
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map2);
        mapFragment.getMapAsync(this);
        yerler.addAll(VT.getAllYer());
        for (i = 0; i < yerler.size(); i++) {
            if (yerler.get(i).equals(isim)) {
                mMap.addMarker(new MarkerOptions().position(new LatLng(VT.getYer(i).getLat(), VT.getYer(i).getLng())).title(i + "'inci nokta"));
            }

        }

        Kayit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(kayitIntent);
                finish();
            }
        });

        Rota.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(rotaIntent);
                finish();
            }
        });


        //dbden verileri çekmek gerek


        // db işlemleri ve gösterim burda yapılıcak.


    }

    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);

    }
}

Upvotes: 1

Related Questions