您好我正在使用webview为Android应用程序创建一个简单的浏览器。
这是我的浏览器类
package com.example.projecta;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
public class Browser extends Activity implements OnClickListener {
EditText addbar;
WebView appbrow;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.easybrowser);
appbrow = (WebView) findViewById(R.layout.easybrowser);
appbrow.loadUrl("http://www.google.com");
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
这是我的清单。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.projecta"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permisson.CAMERA" />
<uses-permission android:maxSdkVersion="19"
android:name="android.permission.SET_WALLPAPER"/>
<uses-permission android:name="android.permission.INTERNET"
android:maxSdkVersion="19"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.projecta.Startbackground"
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="com.example.projecta.Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.projecta.Camera"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.projecta.Browser"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
这是我的logcat
03-16 15:59:36.234: D/dalvikvm(1287): GC_FOR_ALLOC freed 53K, 5% free 3033K/3160K, paused 23ms, total 25ms
03-16 15:59:36.244: I/dalvikvm-heap(1287): Grow heap (frag case) to 4.650MB for 1705616-byte allocation
03-16 15:59:36.294: D/dalvikvm(1287): GC_FOR_ALLOC freed 2K, 3% free 4696K/4828K, paused 40ms, total 40ms
03-16 15:59:36.524: E/MediaPlayer(1287): Should have subtitle controller already set
03-16 15:59:36.764: D/gralloc_goldfish(1287): Emulator without GPU emulation detected.
03-16 15:59:41.874: D/dalvikvm(1287): GC_FOR_ALLOC freed 13K, 2% free 4906K/4988K, paused 26ms, total 27ms
03-16 15:59:41.874: I/dalvikvm-heap(1287): Grow heap (frag case) to 5.928MB for 1127536-byte allocation
03-16 15:59:41.994: D/dalvikvm(1287): GC_FOR_ALLOC freed 1K, 2% free 6005K/6092K, paused 110ms, total 110ms
03-16 15:59:47.184: I/Choreographer(1287): Skipped 85 frames! The application may be doing too much work on its main thread.
03-16 15:59:48.924: V/WebViewChromium(1287): Binding Chromium to the background looper Looper{b1d9afa0}
03-16 15:59:48.934: I/chromium(1287): [INFO:library_loader_hooks.cc(112)] Chromium logging enabled: level = 0, default verbosity = 0
03-16 15:59:48.944: I/BrowserProcessMain(1287): Initializing chromium process, renderers=0
03-16 15:59:49.064: E/chromium(1287): [ERROR:gl_surface_egl.cc(153)] No suitable EGL configs found.
03-16 15:59:49.064: E/chromium(1287): [ERROR:gl_surface_egl.cc(620)] GLSurfaceEGL::InitializeOneOff failed.
03-16 15:59:49.064: E/chromium(1287): [ERROR:gl_surface_egl.cc(153)] No suitable EGL configs found.
03-16 15:59:49.074: E/chromium(1287): [ERROR:gl_surface_egl.cc(620)] GLSurfaceEGL::InitializeOneOff failed.
03-16 15:59:49.074: E/chromium(1287): [ERROR:gpu_info_collector.cc(86)] gfx::GLSurface::InitializeOneOff() failed
03-16 15:59:49.154: W/chromium(1287): [WARNING:proxy_service.cc(888)] PAC support disabled because there is no system implementation
03-16 15:59:49.314: D/AndroidRuntime(1287): Shutting down VM
03-16 15:59:49.314: W/dalvikvm(1287): threadid=1: thread exiting with uncaught exception (group=0xb1ac2b90)
03-16 15:59:49.334: E/AndroidRuntime(1287): FATAL EXCEPTION: main
03-16 15:59:49.334: E/AndroidRuntime(1287): Process: com.example.projecta, PID: 1287
03-16 15:59:49.334: E/AndroidRuntime(1287): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.projecta/com.example.projecta.Browser}: java.lang.NullPointerException
03-16 15:59:49.334: E/AndroidRuntime(1287): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
03-16 15:59:49.334: E/AndroidRuntime(1287): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
03-16 15:59:49.334: E/AndroidRuntime(1287): at android.app.ActivityThread.access$700(ActivityThread.java:135)
03-16 15:59:49.334: E/AndroidRuntime(1287): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
03-16 15:59:49.334: E/AndroidRuntime(1287): at android.os.Handler.dispatchMessage(Handler.java:102)
03-16 15:59:49.334: E/AndroidRuntime(1287): at android.os.Looper.loop(Looper.java:137)
03-16 15:59:49.334: E/AndroidRuntime(1287): at android.app.ActivityThread.main(ActivityThread.java:4998)
03-16 15:59:49.334: E/AndroidRuntime(1287): at java.lang.reflect.Method.invokeNative(Native Method)
03-16 15:59:49.334: E/AndroidRuntime(1287): at java.lang.reflect.Method.invoke(Method.java:515)
03-16 15:59:49.334: E/AndroidRuntime(1287): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
03-16 15:59:49.334: E/AndroidRuntime(1287): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
03-16 15:59:49.334: E/AndroidRuntime(1287): at dalvik.system.NativeStart.main(Native Method)
03-16 15:59:49.334: E/AndroidRuntime(1287): Caused by: java.lang.NullPointerException
03-16 15:59:49.334: E/AndroidRuntime(1287): at com.example.projecta.Browser.onCreate(Browser.java:26)
03-16 15:59:49.334: E/AndroidRuntime(1287): at android.app.Activity.performCreate(Activity.java:5243)
03-16 15:59:49.334: E/AndroidRuntime(1287): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-16 15:59:49.334: E/AndroidRuntime(1287): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
03-16 15:59:49.334: E/AndroidRuntime(1287): ... 11 more
请帮忙。这个应用程序有一个菜单。相机,浏览器
应用程序的相机部分工作正常,但当我点击菜单中的浏览器时,它停止工作。感谢
答案 0 :(得分:1)
appbrow = (WebView) findViewById(R.layout.easybrowser);
应该是
appbrow = (WebView) findViewById(R.id.idWebViewInLayout);