私はAndroidでシンプルなWebViewアプリを実装していました(私はAndroidとJavaが初めてです)。アプリは正常に動作しますが、ボタンをクリックするとこのエラーが発生します。 残念ながら、アプリはエラーを停止しました
エラーログ。
08-26 11:49:06.374: W/dalvikvm(754): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
08-26 11:49:06.444: E/AndroidRuntime(754): FATAL EXCEPTION: main
08-26 11:49:06.444: E/AndroidRuntime(754): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.androidwebviewexample/com.example.androidwebviewexample.WebActivity}; have you declared this activity in your AndroidManifest.xml?
08-26 11:49:06.444: E/AndroidRuntime(754): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
08-26 11:49:06.444: E/AndroidRuntime(754): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
08-26 11:49:06.444: E/AndroidRuntime(754): at android.app.Activity.startActivityForResult(Activity.java:3390)
08-26 11:49:06.444: E/AndroidRuntime(754): at android.app.Activity.startActivityForResult(Activity.java:3351)
08-26 11:49:06.444: E/AndroidRuntime(754): at android.app.Activity.startActivity(Activity.java:3587)
08-26 11:49:06.444: E/AndroidRuntime(754): at android.app.Activity.startActivity(Activity.java:3555)
08-26 11:49:06.444: E/AndroidRuntime(754): at com.example.androidwebviewexample.MainActivity$1.onClick(MainActivity.java:28)
08-26 11:49:06.444: E/AndroidRuntime(754): at android.view.View.performClick(View.java:4240)
08-26 11:49:06.444: E/AndroidRuntime(754): at android.view.View$PerformClick.run(View.java:17721)
08-26 11:49:06.444: E/AndroidRuntime(754): at android.os.Handler.handleCallback(Handler.java:730)
08-26 11:49:06.444: E/AndroidRuntime(754): at android.os.Handler.dispatchMessage(Handler.java:92)
08-26 11:49:06.444: E/AndroidRuntime(754): at android.os.Looper.loop(Looper.java:137)
08-26 11:49:06.444: E/AndroidRuntime(754): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-26 11:49:06.444: E/AndroidRuntime(754): at java.lang.reflect.Method.invokeNative(Native Method)
08-26 11:49:06.444: E/AndroidRuntime(754): at java.lang.reflect.Method.invoke(Method.java:525)
08-26 11:49:06.444: E/AndroidRuntime(754): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-26 11:49:06.444: E/AndroidRuntime(754): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-26 11:49:06.444: E/AndroidRuntime(754): at dalvik.system.NativeStart.main(Native Method)
私はこのチュートリアルに従っています。
ここに私のコードがあります:
MainActivity.java
package com.example.androidwebviewexample;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private Button button;
public void onCreate(Bundle savedInstanceState) {
final Context context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button)findViewById(R.id.buttonUrl);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, WebActivity.class);
startActivity(intent);
}
});
}
}
WebActivity.java パッケージ com.example.androidwebviewexample;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webcontent);
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.random.com/");
}
}
androidmanifesto.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidwebviewexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.androidwebviewexample.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>
</application>
</manifest>