Android Studio中无法找到明确的活动类 [英] Android Studio unable to find explicit activity class
问题描述
我有一个应用程序,它可以让我改变/添加/ mysql数据库中删除。该应用程序打开了罚款,当我运行它,但是当我尝试点击ViewAllEmployee按钮,我不断收到一个错误说无法找到明确的活动类。我在网上看了看,并试图之前工作过的人这个问题的所有解决方案。我已经加入到我的AndroidManifest太多,但它仍然不想工作。任何人都可以帮忙吗?从字面上一直在努力解决这个问题了几个小时!
AndroidManifest.xml中
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.assignment.androidassignment
安卓版code =1
机器人:=的versionName1.0><使用许可权的android:NAME =android.permission.INTERNET对/><用途-SDK
安卓的minSdkVersion =18
机器人:targetSdkVersion =21/><应用
机器人:allowBackup =真
机器人:标签=@字符串/ APP_NAME>
<活动
机器人:名字=com.example.assignment.androidassignment.MainActivity
机器人:标签=@字符串/ APP_NAME
机器人:主题=@安卓风格/ Theme.Holo.Dialog>&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器> <活动
机器人:名字=com.example.assignment.androidassignment.ViewAllEmployee
/>
< /活性GT;
< /用途>< /清单>
MainActivity.java - 显示'ViewAllEmployee'被点击的onClick时出错:
包com.example.assignment.androidassignment;进口android.app.Activity;
进口android.app.ProgressDialog;
进口android.content.Intent;
进口android.os.AsyncTask;
进口android.os.Bundle;
进口android.view.View;
进口android.widget.Button;
进口android.widget.EditText;
进口android.widget.Toast;
进口的java.util.HashMap;公共类MainActivity扩展活动实现View.OnClickListener {//定义视图
私人的EditText editTextLatitude;
私人的EditText editTextLongitude;
私人的EditText editTextTimeInserted;私人按钮buttonAdd;
私人按钮buttonView;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main); //初始化意见
editTextLatitude =(EditText上)findViewById(R.id.editTextLat);
editTextLongitude =(EditText上)findViewById(R.id.editTextLon);
editTextTimeInserted =(EditText上)findViewById(R.id.editTextTimeInserted); buttonAdd =(按钮)findViewById(R.id.buttonAdd);
buttonView =(按钮)findViewById(R.id.buttonView); //设置监听器按钮
buttonAdd.setOnClickListener(本);
buttonView.setOnClickListener(本);
}
//增加雇员
私人无效addEmployee(){ 最后弦乐经纬度= editTextLatitude.getText()的toString()修剪()。
。最后弦乐LON = editTextLongitude.getText()的toString()修剪();
最后弦乐timeInserted = editTextTimeInserted.getText()的toString()修剪()。 类AddEmployee扩展的AsyncTask<太虚,太虚,字符串> { ProgressDialog负荷; @覆盖
在preExecute保护无效(){
super.on preExecute();
装载= ProgressDialog.show(MainActivity.this添加...,稍候...,假的,假的);
} @覆盖
保护无效onPostExecute(String s)将{
super.onPostExecute(多个);
loading.dismiss();
Toast.makeText(MainActivity.this,S,Toast.LENGTH_LONG).show();
} @覆盖
保护字符串doInBackground(无效... V){
HashMap的<字符串,字符串> PARAMS =新的HashMap<>();
params.put(Config.KEY_LAT,LAT);
params.put(Config.KEY_LON,LON);
params.put(Config.KEY_TIMEINSERTED,timeInserted); RequestHandler RH =新RequestHandler();
字符串资源= rh.sendPostRequest(Config.URL_ADD,则params);
返回水库;
}
} AddEmployee AE =新AddEmployee();
ae.execute();
} @覆盖
公共无效的onClick(视图v){
如果(V == buttonAdd){
addEmployee();
} 如果(V == buttonView){
startActivity(新意图(这一点,com.example.assignment.androidassignment.ViewAllEmployee.class));
}
}
}
LogCat中的错误:
三月12日至九日:34:46.634 2489年至2489年/? E / AndroidRuntime:致命异常:主要
=过程:com.example.assignment.androidassignment,PID:2489
android.content.ActivityNotFoundException:无法找到明确的活动类{com.example.assignment.androidassignment / com.example.assignment.androidassignment.ViewAllEmployee};有你宣布你的AndroidManifest.xml这个活动?
在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
在android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
在android.app.Activity.startActivityForResult(Activity.java:3424)
在android.app.Activity.startActivityForResult(Activity.java:3385)
在android.app.Activity.startActivity(Activity.java:3627)
在android.app.Activity.startActivity(Activity.java:3595)
在com.example.assignment.androidassignment.MainActivity.onClick(MainActivity.java:91)
在android.view.View.performClick(View.java:4438)
在android.view.View $ PerformClick.run(View.java:18422)
在android.os.Handler.handleCallback(Handler.java:733)
在android.os.Handler.dispatchMessage(Handler.java:95)
在android.os.Looper.loop(Looper.java:136)
在android.app.ActivityThread.main(ActivityThread.java:5001)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:515)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:785)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
在dalvik.system.NativeStart.main(本机方法)
如果(V == buttonView){
startActivity(新意图(这一点,com.example.assignment.androidassignment.ViewAllEmployee.class));
}
到
如果(V == buttonView){
startActivity(新意图(MainActivity.this,ViewAllEmployee.class));
}
从
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.assignment.androidassignment
安卓版code =1
机器人:=的versionName1.0><使用许可权的android:NAME =android.permission.INTERNET对/><用途-SDK
安卓的minSdkVersion =18
机器人:targetSdkVersion =21/><应用
机器人:allowBackup =真
机器人:标签=@字符串/ APP_NAME>
<活动
机器人:名字=com.example.assignment.androidassignment.MainActivity
机器人:标签=@字符串/ APP_NAME
机器人:主题=@安卓风格/ Theme.Holo.Dialog>&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器> <活动
机器人:名字=com.example.assignment.androidassignment.ViewAllEmployee
/>
< /活性GT;
< /用途>< /清单>
到
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.assignment.androidassignment
安卓版code =1
机器人:=的versionName1.0><使用许可权的android:NAME =android.permission.INTERNET对/><用途-SDK
安卓的minSdkVersion =18
机器人:targetSdkVersion =21/><应用
机器人:allowBackup =真
机器人:标签=@字符串/ APP_NAME>
<活动
机器人:名字=com.example.assignment.androidassignment.MainActivity
机器人:标签=@字符串/ APP_NAME
机器人:主题=@安卓风格/ Theme.Holo.Dialog>&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
<活动
机器人:名字=com.example.assignment.androidassignment.ViewAllEmployee
/>
< /用途>< /清单>
请更改上面的,这是因为里面清单活动的嵌套发生 P>
i have a application that allows me to alter/add/delete from mysql database. The application opens up fine when i run it but when i try clicking on the 'ViewAllEmployee' button i keep getting a error saying it cannot find explicit activity class. I have looked online and tried all solutions that have worked for people with this problem before. I have added it into my AndroidManifest too but it still doesn't want to work. Can anyone help? Literally been trying to fix this for hours!
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.assignment.androidassignment"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:label="@string/app_name" >
<activity
android:name="com.example.assignment.androidassignment.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Dialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity
android:name="com.example.assignment.androidassignment.ViewAllEmployee"
/>
</activity>
</application>
</manifest>
MainActivity.java -- Error showing when onClick for 'ViewAllEmployee' is clicked:
package com.example.assignment.androidassignment;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.HashMap;
public class MainActivity extends Activity implements View.OnClickListener{
//Defining views
private EditText editTextLatitude;
private EditText editTextLongitude;
private EditText editTextTimeInserted;
private Button buttonAdd;
private Button buttonView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Initializing views
editTextLatitude = (EditText) findViewById(R.id.editTextLat);
editTextLongitude = (EditText) findViewById(R.id.editTextLon);
editTextTimeInserted = (EditText) findViewById(R.id.editTextTimeInserted);
buttonAdd = (Button) findViewById(R.id.buttonAdd);
buttonView = (Button) findViewById(R.id.buttonView);
//Setting listeners to button
buttonAdd.setOnClickListener(this);
buttonView.setOnClickListener(this);
}
//Adding an employee
private void addEmployee(){
final String lat = editTextLatitude.getText().toString().trim();
final String lon = editTextLongitude.getText().toString().trim();
final String timeInserted = editTextTimeInserted.getText().toString().trim();
class AddEmployee extends AsyncTask<Void,Void,String>{
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(MainActivity.this,"Adding...","Wait...",false,false);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(MainActivity.this,s,Toast.LENGTH_LONG).show();
}
@Override
protected String doInBackground(Void... v) {
HashMap<String,String> params = new HashMap<>();
params.put(Config.KEY_LAT,lat);
params.put(Config.KEY_LON,lon);
params.put(Config.KEY_TIMEINSERTED,timeInserted);
RequestHandler rh = new RequestHandler();
String res = rh.sendPostRequest(Config.URL_ADD, params);
return res;
}
}
AddEmployee ae = new AddEmployee();
ae.execute();
}
@Override
public void onClick(View v) {
if(v == buttonAdd){
addEmployee();
}
if(v == buttonView){
startActivity(new Intent(this,com.example.assignment.androidassignment.ViewAllEmployee.class));
}
}
}
LogCat errors:
12-09 03:34:46.634 2489-2489/? E/AndroidRuntime: FATAL EXCEPTION: main
=Process: com.example.assignment.androidassignment, PID: 2489
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.assignment.androidassignment/com.example.assignment.androidassignment.ViewAllEmployee}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
at android.app.Activity.startActivityForResult(Activity.java:3424)
at android.app.Activity.startActivityForResult(Activity.java:3385)
at android.app.Activity.startActivity(Activity.java:3627)
at android.app.Activity.startActivity(Activity.java:3595)
at com.example.assignment.androidassignment.MainActivity.onClick(MainActivity.java:91)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
from
if(v == buttonView){
startActivity(new Intent(this,com.example.assignment.androidassignment.ViewAllEmployee.class));
}
to
if(v == buttonView){
startActivity(new Intent(MainActivity.this,ViewAllEmployee.class));
}
from
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.assignment.androidassignment"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:label="@string/app_name" >
<activity
android:name="com.example.assignment.androidassignment.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Dialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity
android:name="com.example.assignment.androidassignment.ViewAllEmployee"
/>
</activity>
</application>
</manifest>
to
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.assignment.androidassignment"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:label="@string/app_name" >
<activity
android:name="com.example.assignment.androidassignment.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Dialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.assignment.androidassignment.ViewAllEmployee"
/>
</application>
</manifest>
please change the above and this is happening because of nesting of activity inside manifest
这篇关于Android Studio中无法找到明确的活动类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!