我正在尝试创建一个简单的程序,当它运行时显示一个按钮,当用户单击该按钮时,它们将被带到一个网页。但是,我一直收到“找不到处理意图的活动”错误。这是我目前的清单文件中的内容:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="school.project.application"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="school.project.application.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=".AppPreferenceActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.Intent.ACTION_VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
这是我在点击按钮时用来启动网页的代码: package school.project.application;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.content.Intent;
import android.os.Bundle;
import android.net.Uri;
public class MainActivity extends Activity {
private final String TAG = "sendButton";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupsendMessage();
}
private void setupsendMessage() {
// do something when the button is pressed
//
Button sendButton = (Button) findViewById(R.id.button1);
sendButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Log.i(TAG, "You Clicked a button");
goToUrl("htpp://stackoverflow.com/");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void goToSo (View view){
goToUrl("http://stackoverflow.com/");
}
private void goToUrl(String url){
Uri uriUrl = Uri.parse(url);
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}
}
我想知道是否有人可以花一些时间来帮我纠正这个问题? 非常感谢你们。
编辑: 这是堆栈跟踪:
11-20 20:38:22.845: I/sendButton(3212): You Clicked a button
11-20 20:38:22.845: W/dalvikvm(3212): threadid=1: thread exiting with uncaught exception (group=0x4001f560)
11-20 20:38:22.845: E/AndroidRuntime(3212): FATAL EXCEPTION: main
11-20 20:38:22.845: E/AndroidRuntime(3212): android.content.ActivityNotFoundException: No Activity found to handle Intent { }
11-20 20:38:22.845: E/AndroidRuntime(3212): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
11-20 20:38:22.845: E/AndroidRuntime(3212): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
11-20 20:38:22.845: E/AndroidRuntime(3212): at android.app.Activity.startActivityForResult(Activity.java:2827)
11-20 20:38:22.845: E/AndroidRuntime(3212): at android.app.Activity.startActivity(Activity.java:2933)
11-20 20:38:22.845: E/AndroidRuntime(3212): at school.project.application.MainActivity.goToUrl(MainActivity.java:64)
11-20 20:38:22.845: E/AndroidRuntime(3212): at school.project.application.MainActivity.access$0(MainActivity.java:61)
11-20 20:38:22.845: E/AndroidRuntime(3212): at school.project.application.MainActivity$1.onClick(MainActivity.java:42)
11-20 20:38:22.845: E/AndroidRuntime(3212): at android.view.View.performClick(View.java:2485)
11-20 20:38:22.845: E/AndroidRuntime(3212): at android.view.View$PerformClick.run(View.java:9081)
11-20 20:38:22.845: E/AndroidRuntime(3212): at android.os.Handler.handleCallback(Handler.java:587)
11-20 20:38:22.845: E/AndroidRuntime(3212): at android.os.Handler.dispatchMessage(Handler.java:92)
11-20 20:38:22.845: E/AndroidRuntime(3212): at android.os.Looper.loop(Looper.java:130)
11-20 20:38:22.845: E/AndroidRuntime(3212): at android.app.ActivityThread.main(ActivityThread.java:3696)
11-20 20:38:22.845: E/AndroidRuntime(3212): at java.lang.reflect.Method.invokeNative(Native Method)
11-20 20:38:22.845: E/AndroidRuntime(3212): at java.lang.reflect.Method.invoke(Method.java:507)
11-20 20:38:22.845: E/AndroidRuntime(3212): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
11-20 20:38:22.845: E/AndroidRuntime(3212): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
11-20 20:38:22.845: E/AndroidRuntime(3212): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:2)