我有问题启动我的应用程序,试图找到问题4小时。我是android开发的新手。可以尝试为应用程序制作启动画面,然后加载webview网站。 这是我的代码。
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.uwsolutionssupport"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<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=".UniqueActivity"
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=".myMainScreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.tutorial.CLEARSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
activity_unique.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainWebView">
</WebView>
</LinearLayout>
myMainScreen.java
package com.tutorial.myapp;
import android.app.Activity; import android.os.Bundle;
import com.example.uwsolutionssupport.R;
public class myMainScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_unique);
}
}
UniqueActivity.java
package com.example.uwsolutionssupport;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class UniqueActivity extends Activity {
/** Called when the activity is first created. */
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread logoTimer = new Thread() {
public void run(){
try{
int logoTimer = 0;
while(logoTimer < 5000){
sleep(100);
logoTimer = logoTimer +100;
};
startActivity(new Intent("com.tutorial.CLEARSCREEN"));
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
finish();
}
}
};
logoTimer.start();
WebView mainWebView = (WebView) findViewById(R.id.mainWebView);
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mainWebView.setWebViewClient(new MyCustomWebViewClient());
mainWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mainWebView.loadUrl("http://unique-websolutions.com/support/public/login");
}
private class MyCustomWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
logcat的
02-16 20:35:34.939: D/dalvikvm(1102): GC_FOR_ALLOC freed 74K, 5% free 2809K/2952K, paused 70ms, total 72ms
02-16 20:35:34.939: I/dalvikvm-heap(1102): Grow heap (frag case) to 4.126MB for 1382416-byte allocation
02-16 20:35:35.019: D/dalvikvm(1102): GC_FOR_ALLOC freed <1K, 4% free 4159K/4304K, paused 72ms, total 72ms
02-16 20:35:35.319: D/AndroidRuntime(1102): Shutting down VM
02-16 20:35:35.319: W/dalvikvm(1102): threadid=1: thread exiting with uncaught exception (group=0xb2abbba8)
02-16 20:35:35.369: E/AndroidRuntime(1102): FATAL EXCEPTION: main
02-16 20:35:35.369: E/AndroidRuntime(1102): Process: com.example.uwsolutionssupport, PID: 1102
02-16 20:35:35.369: E/AndroidRuntime(1102): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.uwsolutionssupport/com.example.uwsolutionssupport.UniqueActivity}: java.lang.NullPointerException
02-16 20:35:35.369: E/AndroidRuntime(1102): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-16 20:35:35.369: E/AndroidRuntime(1102): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-16 20:35:35.369: E/AndroidRuntime(1102): at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-16 20:35:35.369: E/AndroidRuntime(1102): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-16 20:35:35.369: E/AndroidRuntime(1102): at android.os.Handler.dispatchMessage(Handler.java:102)
02-16 20:35:35.369: E/AndroidRuntime(1102): at android.os.Looper.loop(Looper.java:136)
02-16 20:35:35.369: E/AndroidRuntime(1102): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-16 20:35:35.369: E/AndroidRuntime(1102): at java.lang.reflect.Method.invokeNative(Native Method)
02-16 20:35:35.369: E/AndroidRuntime(1102): at java.lang.reflect.Method.invoke(Method.java:515)
02-16 20:35:35.369: E/AndroidRuntime(1102): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-16 20:35:35.369: E/AndroidRuntime(1102): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-16 20:35:35.369: E/AndroidRuntime(1102): at dalvik.system.NativeStart.main(Native Method)
02-16 20:35:35.369: E/AndroidRuntime(1102): Caused by: java.lang.NullPointerException
02-16 20:35:35.369: E/AndroidRuntime(1102): at com.example.uwsolutionssupport.UniqueActivity.onCreate(UniqueActivity.java:46)
02-16 20:35:35.369: E/AndroidRuntime(1102): at android.app.Activity.performCreate(Activity.java:5231)
02-16 20:35:35.369: E/AndroidRuntime(1102): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-16 20:35:35.369: E/AndroidRuntime(1102): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-16 20:35:35.369: E/AndroidRuntime(1102): ... 11 more
02-16 20:36:36.759: I/Process(1102): Sending signal. PID: 1102 SIG: 9
02-16 20:36:38.249: D/AndroidRuntime(1159): Shutting down VM
02-16 20:36:38.249: W/dalvikvm(1159): threadid=1: thread exiting with uncaught exception (group=0xb2abbba8)
02-16 20:36:38.309: E/AndroidRuntime(1159): FATAL EXCEPTION: main
02-16 20:36:38.309: E/AndroidRuntime(1159): Process: com.example.uwsolutionssupport, PID: 1159
02-16 20:36:38.309: E/AndroidRuntime(1159): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.uwsolutionssupport/com.example.uwsolutionssupport.myMainScreen}: java.lang.ClassNotFoundException: Didn't find class "com.example.uwsolutionssupport.myMainScreen" on path: DexPathList[[zip file "/data/app/com.example.uwsolutionssupport-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.uwsolutionssupport-2, /system/lib]]
02-16 20:36:38.309: E/AndroidRuntime(1159): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
02-16 20:36:38.309: E/AndroidRuntime(1159): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-16 20:36:38.309: E/AndroidRuntime(1159): at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-16 20:36:38.309: E/AndroidRuntime(1159): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-16 20:36:38.309: E/AndroidRuntime(1159): at android.os.Handler.dispatchMessage(Handler.java:102)
02-16 20:36:38.309: E/AndroidRuntime(1159): at android.os.Looper.loop(Looper.java:136)
02-16 20:36:38.309: E/AndroidRuntime(1159): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-16 20:36:38.309: E/AndroidRuntime(1159): at java.lang.reflect.Method.invokeNative(Native Method)
02-16 20:36:38.309: E/AndroidRuntime(1159): at java.lang.reflect.Method.invoke(Method.java:515)
02-16 20:36:38.309: E/AndroidRuntime(1159): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-16 20:36:38.309: E/AndroidRuntime(1159): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-16 20:36:38.309: E/AndroidRuntime(1159): at dalvik.system.NativeStart.main(Native Method)
02-16 20:36:38.309: E/AndroidRuntime(1159): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.uwsolutionssupport.myMainScreen" on path: DexPathList[[zip file "/data/app/com.example.uwsolutionssupport-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.uwsolutionssupport-2, /system/lib]]
02-16 20:36:38.309: E/AndroidRuntime(1159): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
02-16 20:36:38.309: E/AndroidRuntime(1159): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
02-16 20:36:38.309: E/AndroidRuntime(1159): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
02-16 20:36:38.309: E/AndroidRuntime(1159): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
02-16 20:36:38.309: E/AndroidRuntime(1159): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
02-16 20:36:38.309: E/AndroidRuntime(1159): ... 11 more
02-16 20:36:44.409: I/Process(1159): Sending signal. PID: 1159 SIG: 9
02-16 20:36:48.319: D/dalvikvm(1188): GC_FOR_ALLOC freed 47K, 5% free 2809K/2928K, paused 97ms, total 100ms
02-16 20:36:48.319: I/dalvikvm-heap(1188): Grow heap (frag case) to 4.126MB for 1382416-byte allocation
02-16 20:36:48.399: D/dalvikvm(1188): GC_FOR_ALLOC freed <1K, 3% free 4159K/4280K, paused 70ms, total 70ms
02-16 20:36:48.689: D/AndroidRuntime(1188): Shutting down VM
02-16 20:36:48.689: W/dalvikvm(1188): threadid=1: thread exiting with uncaught exception (group=0xb2abbba8)
02-16 20:36:48.749: E/AndroidRuntime(1188): FATAL EXCEPTION: main
02-16 20:36:48.749: E/AndroidRuntime(1188): Process: com.example.uwsolutionssupport, PID: 1188
02-16 20:36:48.749: E/AndroidRuntime(1188): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.uwsolutionssupport/com.example.uwsolutionssupport.UniqueActivity}: java.lang.NullPointerException
02-16 20:36:48.749: E/AndroidRuntime(1188): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-16 20:36:48.749: E/AndroidRuntime(1188): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-16 20:36:48.749: E/AndroidRuntime(1188): at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-16 20:36:48.749: E/AndroidRuntime(1188): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-16 20:36:48.749: E/AndroidRuntime(1188): at android.os.Handler.dispatchMessage(Handler.java:102)
02-16 20:36:48.749: E/AndroidRuntime(1188): at android.os.Looper.loop(Looper.java:136)
02-16 20:36:48.749: E/AndroidRuntime(1188): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-16 20:36:48.749: E/AndroidRuntime(1188): at java.lang.reflect.Method.invokeNative(Native Method)
02-16 20:36:48.749: E/AndroidRuntime(1188): at java.lang.reflect.Method.invoke(Method.java:515)
02-16 20:36:48.749: E/AndroidRuntime(1188): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-16 20:36:48.749: E/AndroidRuntime(1188): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-16 20:36:48.749: E/AndroidRuntime(1188): at dalvik.system.NativeStart.main(Native Method)
02-16 20:36:48.749: E/AndroidRuntime(1188): Caused by: java.lang.NullPointerException
02-16 20:36:48.749: E/AndroidRuntime(1188): at com.example.uwsolutionssupport.UniqueActivity.onCreate(UniqueActivity.java:46)
02-16 20:36:48.749: E/AndroidRuntime(1188): at android.app.Activity.performCreate(Activity.java:5231)
02-16 20:36:48.749: E/AndroidRuntime(1188): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-16 20:36:48.749: E/AndroidRuntime(1188): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-16 20:36:48.749: E/AndroidRuntime(1188): ... 11 more
02-16 20:38:27.789: D/dalvikvm(1257): GC_FOR_ALLOC freed 55K, 5% free 2809K/2932K, paused 71ms, total 74ms
02-16 20:38:27.789: I/dalvikvm-heap(1257): Grow heap (frag case) to 4.126MB for 1382416-byte allocation
02-16 20:38:27.859: D/dalvikvm(1257): GC_FOR_ALLOC freed <1K, 3% free 4159K/4284K, paused 60ms, total 60ms
02-16 20:38:28.089: D/AndroidRuntime(1257): Shutting down VM
02-16 20:38:28.089: W/dalvikvm(1257): threadid=1: thread exiting with uncaught exception (group=0xb2abbba8)
02-16 20:38:28.139: E/AndroidRuntime(1257): FATAL EXCEPTION: main
02-16 20:38:28.139: E/AndroidRuntime(1257): Process: com.example.uwsolutionssupport, PID: 1257
02-16 20:38:28.139: E/AndroidRuntime(1257): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.uwsolutionssupport/com.example.uwsolutionssupport.UniqueActivity}: java.lang.NullPointerException
02-16 20:38:28.139: E/AndroidRuntime(1257): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-16 20:38:28.139: E/AndroidRuntime(1257): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-16 20:38:28.139: E/AndroidRuntime(1257): at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-16 20:38:28.139: E/AndroidRuntime(1257): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-16 20:38:28.139: E/AndroidRuntime(1257): at android.os.Handler.dispatchMessage(Handler.java:102)
02-16 20:38:28.139: E/AndroidRuntime(1257): at android.os.Looper.loop(Looper.java:136)
02-16 20:38:28.139: E/AndroidRuntime(1257): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-16 20:38:28.139: E/AndroidRuntime(1257): at java.lang.reflect.Method.invokeNative(Native Method)
02-16 20:38:28.139: E/AndroidRuntime(1257): at java.lang.reflect.Method.invoke(Method.java:515)
02-16 20:38:28.139: E/AndroidRuntime(1257): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-16 20:38:28.139: E/AndroidRuntime(1257): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-16 20:38:28.139: E/AndroidRuntime(1257): at dalvik.system.NativeStart.main(Native Method)
02-16 20:38:28.139: E/AndroidRuntime(1257): Caused by: java.lang.NullPointerException
02-16 20:38:28.139: E/AndroidRuntime(1257): at com.example.uwsolutionssupport.UniqueActivity.onCreate(UniqueActivity.java:46)
02-16 20:38:28.139: E/AndroidRuntime(1257): at android.app.Activity.performCreate(Activity.java:5231)
02-16 20:38:28.139: E/AndroidRuntime(1257): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-16 20:38:28.139: E/AndroidRuntime(1257): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-16 20:38:28.139: E/AndroidRuntime(1257): ... 11 more
答案 0 :(得分:0)
NullPointerException
中第46行有一个UniqueActivity.java
。
第46行是这行吗?
WebView mainWebView = (WebView) findViewById(R.id.mainWebView);
WebSettings webSettings = mainWebView.getSettings(); // throws NullPointer because mainWebView is null
然后你可能使用了错误的id。
顺便说一下。你的线程是非常丑陋的,会泄漏记忆(Android: why Thread in getView() does not seem to work?)...使用[Handler.postDelayed()](http://developer.android.com/reference/android/os/Handler.html#postDelayed(java.lang.Runnable,long))或Timer并且不要忘记取消Activity.onDestroy()