0

我在 Eclipse 中运行应用程序时遇到问题,我无法弄清楚问题所在。因为项目文件中没有错误。我已经重新安装了eclipse,之后我遇到了问题。文件

package com.goby.bus;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class GobybusActivity extends Activity {
    WebView mWebView;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl("file:///android_asset/index.html");
        mWebView.setWebViewClient(new mWebViewClient());
        mWebView.setBackgroundColor(Color.WHITE);
    }



    private class mWebViewClient extends WebViewClient {        

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }

}

日志文件:

04-22 11:21:54.508: D/AndroidRuntime(623): Shutting down VM
04-22 11:21:54.528: W/dalvikvm(623): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-22 11:21:54.618: E/AndroidRuntime(623): FATAL EXCEPTION: main
04-22 11:21:54.618: E/AndroidRuntime(623): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.goby.bus/com.goby.bus.MainActivity}: java.lang.ClassNotFoundException: com.goby.bus.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.goby.bus-1.apk]
04-22 11:21:54.618: E/AndroidRuntime(623):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
04-22 11:21:54.618: E/AndroidRuntime(623):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-22 11:21:54.618: E/AndroidRuntime(623):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-22 11:21:54.618: E/AndroidRuntime(623):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-22 11:21:54.618: E/AndroidRuntime(623):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-22 11:21:54.618: E/AndroidRuntime(623):  at android.os.Looper.loop(Looper.java:123)
04-22 11:21:54.618: E/AndroidRuntime(623):  at android.app.ActivityThread.main(ActivityThread.java:4627)
04-22 11:21:54.618: E/AndroidRuntime(623):  at java.lang.reflect.Method.invokeNative(Native Method)
04-22 11:21:54.618: E/AndroidRuntime(623):  at java.lang.reflect.Method.invoke(Method.java:521)
04-22 11:21:54.618: E/AndroidRuntime(623):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-22 11:21:54.618: E/AndroidRuntime(623):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-22 11:21:54.618: E/AndroidRuntime(623):  at dalvik.system.NativeStart.main(Native Method)
04-22 11:21:54.618: E/AndroidRuntime(623): Caused by: java.lang.ClassNotFoundException: com.goby.bus.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.goby.bus-1.apk]
04-22 11:21:54.618: E/AndroidRuntime(623):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-22 11:21:54.618: E/AndroidRuntime(623):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-22 11:21:54.618: E/AndroidRuntime(623):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-22 11:21:54.618: E/AndroidRuntime(623):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-22 11:21:54.618: E/AndroidRuntime(623):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)

欢迎大家回复。。。

4

2 回答 2

3

似乎 XML 中指定的活动名称与您的类名称不匹配,如下行所示:

04-22 11:21:54.618: E/AndroidRuntime(623): 由: java.lang.ClassNotFoundException: com.goby.bus.MainActivity in loader dalvik.system.PathClassLoader [/data/app/com.goby.bus -1.apk]

在您的 android 清单 XML 中,更改

<activity android:name=".MainActivity "  ... >

<activity android:name=".GobybusActivity"  ... >
于 2012-04-22T06:00:18.477 回答
0

移动

WebView mWebView;

以上

mWebView = (WebView) findViewById(R.id.webview);
于 2014-12-04T22:12:24.757 回答