gpt4 book ai didi

java - Activity 错误甚至认为它在 list 中声明

转载 作者:行者123 更新时间:2023-12-01 09:50:26 24 4
gpt4 key购买 nike

首先,我想说我使用每个中引用的 2 个 Intent 来更改它们之间的 Activity ,我也可以带着 Intent 移动到此类,但是当我尝试从此类启动activty 时,它崩溃了。

这是我收到错误的类。

    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);

}
}

这是android的manifest.xml文件

<?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>

这是错误的 logcat

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)

最佳答案

像这样更改代码;将 Intent 声明放在 oncreate 方法中似乎可以解决问题

    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);

}
}

关于java - Activity 错误甚至认为它在 list 中声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37642166/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com