Hi I am very new to android development. I am currently working on a
webapp for an android tablet. I am trying to implement transitions
between pages using FlipView. However, every time I launch the app,
the process crashes. If anyone can take a look at my code and tell me
what I am doing wrong I would greatly appreciate it. Thank you.
Logs:
03-15 17:53:49.899: E/AndroidRuntime(970): FATAL EXCEPTION: main
03-15 17:53:49.899: E/AndroidRuntime(970): java.lang.RuntimeException:
Unable to start activity ComponentInfo{activity.java/
activity.java.CheckInKioskActivity}: java.lang.NullPointerException
03-15 17:53:49.899: E/AndroidRuntime(970): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
1815)
03-15 17:53:49.899: E/AndroidRuntime(970): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
1831)
03-15 17:53:49.899: E/AndroidRuntime(970): at
android.app.ActivityThread.access$500(ActivityThread.java:122)
03-15 17:53:49.899: E/AndroidRuntime(970): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
03-15 17:53:49.899: E/AndroidRuntime(970): at
android.os.Handler.dispatchMessage(Handler.java:99)
03-15 17:53:49.899: E/AndroidRuntime(970): at
android.os.Looper.loop(Looper.java:132)
03-15 17:53:49.899: E/AndroidRuntime(970): at
android.app.ActivityThread.main(ActivityThread.java:4123)
03-15 17:53:49.899: E/AndroidRuntime(970): at
java.lang.reflect.Method.invokeNative(Native Method)
03-15 17:53:49.899: E/AndroidRuntime(970): at
java.lang.reflect.Method.invoke(Method.java:491)
03-15 17:53:49.899: E/AndroidRuntime(970): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:841)
03-15 17:53:49.899: E/AndroidRuntime(970): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
03-15 17:53:49.899: E/AndroidRuntime(970): at
dalvik.system.NativeStart.main(Native Method)
03-15 17:53:49.899: E/AndroidRuntime(970): Caused by:
java.lang.NullPointerException
03-15 17:53:49.899: E/AndroidRuntime(970): at
android.view.ViewGroup.addView(ViewGroup.java:2850)
03-15 17:53:49.899: E/AndroidRuntime(970): at
android.view.ViewGroup.addView(ViewGroup.java:2837)
03-15 17:53:49.899: E/AndroidRuntime(970): at
activity.java.CheckInKioskActivity.onCreate(CheckInKioskActivity.java:
28)
03-15 17:53:49.899: E/AndroidRuntime(970): at
android.app.Activity.performCreate(Activity.java:4397)
03-15 17:53:49.899: E/AndroidRuntime(970): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1048)
03-15 17:53:49.899: E/AndroidRuntime(970): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
1779)
03-15 17:53:49.899: E/AndroidRuntime(970): ... 11 more
Main Activity:
package activity.java;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.ViewFlipper;
public class CheckInKioskActivity extends Activity {
/** Called when the activity is first created. */
//Init objects
WebView mWebView;
WebView mWebView2;
ViewFlipper flip;
Animation slide_in, slide_out;
//create
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Configure objects
slide_in = AnimationUtils.loadAnimation(this,
R.anim.slide_in);
slide_out = AnimationUtils.loadAnimation(this,
R.anim.slide_out);
setViews();
flip.removeAllViews();
setFlip();
mWebView.loadUrl("http://www.thegamebridge.com/Nuesoft2/
Home.html");
mWebView.setWebViewClient(new FirstWebViewClient());
mWebView.setWebViewClient(new SecondWebViewClient());
}
//configure Flip
private void setFlip() {
flip = (ViewFlipper) findViewById(R.id.flipview);
flip.addView(mWebView, 0);
flip.addView(mWebView2, 1);
flip.setInAnimation(slide_in);
flip.setOutAnimation(slide_out);
flip.setDisplayedChild(0);
}
//configure webviews
private void setViews() {
mWebView = (WebView) findViewById(R.id.webview);
mWebView = (WebView) findViewById(R.id.webview2);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setJavaScriptEnabled(true);
}
//Make mWebView a WebViewClient
private class FirstWebViewClient extends WebViewClient {
//Tell mWebview how to handle URL loading.
@Override
public boolean shouldOverrideUrlLoading(WebView view, String
url) {
mWebView2.loadUrl(url);
flip.setDisplayedChild(1);
return true;
}
}
//Make mWebView2 a WebViewClient
private class SecondWebViewClient extends WebViewClient {
//Tell mWebView2 how to hand URL loading.
@Override
public boolean shouldOverrideUrlLoading(WebView view, String
url) {
mWebView.loadUrl(url);
flip.setDisplayedChild(0);
return true;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) &&
mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="activity.java"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="13" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".CheckInKioskActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/layout_article">
<ViewFlipper
android:id="@+id/flipview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</ViewFlipper>
</LinearLayout>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en