-1

i have problem starting my app, trying to find problem 4hours. I'm new to android development. Curently trying making splash screen for app and then loading webview website. Here is my Code.

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
sockeqwe
  • 15,574
  • 24
  • 88
  • 144
uncklegwebdev
  • 62
  • 2
  • 9

1 Answers1

0

There is a NullPointerException in line 46 in UniqueActivity.java.

Is line 46 this line?

WebView mainWebView = (WebView) findViewById(R.id.mainWebView);
WebSettings webSettings = mainWebView.getSettings(); // throws NullPointer because mainWebView is null

Then you probably are using the wrong id.

Btw. your Threading thing is really ugly and will leak memory (Android: why Thread in getView() does not seem to work?) ... Use [Handler.postDelayed()](http://developer.android.com/reference/android/os/Handler.html#postDelayed(java.lang.Runnable, long)) or Timer and don't forget to cancel the Timer in Activity.onDestroy()

Community
  • 1
  • 1
sockeqwe
  • 15,574
  • 24
  • 88
  • 144
  • This is Line 46 in UniqueActivity.java WebSettings webSettings = mainWebView.getSettings(); – uncklegwebdev Feb 17 '15 at 01:52
  • I guess it will crash because `mainWebView` is null, so I think `WebView mainWebView = (WebView) findViewById(R.id.mainWebView);` returns null – sockeqwe Feb 17 '15 at 01:55
  • I just start working with android development. What is the way to fix it ? or is there a way ? – uncklegwebdev Feb 17 '15 at 02:01
  • Don't use `Timer`. Post to a `Handler`. – Kevin Krumwiede Feb 17 '15 at 02:02
  • U think that is a problem ? – uncklegwebdev Feb 17 '15 at 02:03
  • Right, probably its easier to use `Handler.postDelay()`, however you have to cancel the handler as well in `Activity.onDestory()` with `myHandler. removeCallbacksAndMessages(null) ` – sockeqwe Feb 17 '15 at 02:08
  • I started 2 days to work with android functions so my brain is all chaotic, at the far right im watching vides and tutorials and that is how i making code for start. If you can point me right to the problem or send me resolved code i would be thankful. – uncklegwebdev Feb 17 '15 at 02:11
  • `NullPointerException` has nothing to do with android, you should learn java before starting android. Im not gonna explain you what a NullPointer is ... Google for it, I pointed you the lines that cause the NullPointerExcpetion above ... – sockeqwe Feb 17 '15 at 02:13
  • That lines doesnt causing the NullPointer. BUt ok – uncklegwebdev Feb 17 '15 at 02:35