我知道很多人提出了同樣的問題,但我讀了所有的人,我無法找到我的錯誤。Android - 無法找到明確的活動類
至於所有其他問題,我有2個活動。主要的一個創造和意圖,並把一些信息捆綁,第二個接收它。
錯誤日誌
android.content.ActivityNotFoundException: Unable to find explicit activity class
{/com.example.tkota.testintent.MapActivity};
have you declared this activity in your AndroidManifest.xml?
MainActivity:
package com.example.tkota.testintent;
import android.app.ListActivity;
import android.content.Intent;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.view.View;
import android.os.Bundle;
public class MainActivity extends ListActivity{
String[] strings= {"Test 1","Test 2"};
Intent intent = new Intent(this,MapActivity.class);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, strings));
}
public void onListItemClick(ListView parent, View v, int position, long id){
Bundle bundle = new Bundle();
bundle.putString("string", strings[position]);
intent.putExtras(bundle);
startActivity(intent);
}
}
MapActivity:
package com.example.tkota.testintent;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
public class MapActivity extends Activity{
Button actualizar;
EditText txtDireccion;
WebView myWebView;
public String direccion = new String("");
public String urlDefault = new String("http://maps.google.com/maps?q=");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
actualizar = (Button) this.findViewById(R.id.btnActualizar);
txtDireccion = (EditText) this.findViewById(R.id.txtDireccion);
myWebView = (WebView) this.findViewById(R.id.webView);
Bundle bundle = this.getIntent().getExtras();
direccion = bundle.getString("string");
txtDireccion.setText(direccion);
myWebView.loadUrl(urlDefault+direccion);
}
}
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tkota.testintent" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MapActivity"
android:label="TestIntent"/>
</application>
</manifest>
我閱讀了這些答案https://stackoverflow.com/a/9552169/2257448,我更新了所有Android API和Eclipse。問題仍然存在,所以我在Android Studio上創建了相同的應用程序,仍然沒有解決方案。
我試圖把這個完整的包信息也放在這個清單上。
<activity
android:name="com.example.tkota.testintent.MapActivity"
android:label="TestIntent"/>
任何想法?
編輯
由於Karan Mer寫上註釋的問題是通過創建內部onListItemClick
意圖解決這樣的代碼將是這些:
package com.example.tkota.testintent;
import android.app.ListActivity;
import android.content.Intent;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.view.View;
import android.os.Bundle;
public class MainActivity extends ListActivity{
String[] strings= {"Test 1","Test 2"};
Intent intent = new Intent(this,MapActivity.class);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, strings));
}
public void onListItemClick(ListView parent, View v, int position, long id){
Intent intent = new Intent(MainActivity.this,MapActivity.class);
Bundle bundle = new Bundle();
bundle.putString("string", strings[position]);
intent.putExtras(bundle);
startActivity(intent);
}
}
您是否清理並重建項目? – 2015-03-13 10:54:39
嘗試在下面的'listonitemclick'中創建你的意圖'public void onListItemClick(ListView parent,View v,int position,long id){ Bundle bundle = new Bundle(); intent = new Intent(getapplicationcontext(),MapActivity.class); bundle.putString(「string」,strings [position]); 意圖。putExtras(束); startActivity(intent); }' – 2015-03-13 10:55:53
是的,我在Eclipse上做過,但沒有工作,我只在Android Studio上創建了一個新的工程,並且沒有工作。這是奇怪的事情 – Fernando 2015-03-13 10:56:24