请帮助我了解为什么我的应用程序没有运行。我想检查刷卡是否有效,但它甚至不会在模拟器上启动。由于我对 androing 编程非常陌生,因此我找不到错误所在,因为没有编译器错误。
活动代码:包 enn.ericsson.sitezoeker;
import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;
public class MainActivity extends Activity {
ViewFlipper viewFlipper = GlobalVars.viewFlipper;
Animation slideLeftIn = GlobalVars.slideLeftIn;
Animation slideLeftOut = GlobalVars.slideLeftOut;
Animation slideRightIn = GlobalVars.slideRightIn;
Animation slideRightOut = GlobalVars.slideRightOut;
GestureDetector gestureDetector = GlobalVars.gestureDetector;
View.OnTouchListener gestureListener = GlobalVars.gestureListener;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
viewFlipper = (ViewFlipper) findViewById(R.id.flipper);
slideLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
slideLeftOut = AnimationUtils
.loadAnimation(this, R.anim.slide_left_out);
slideRightIn = AnimationUtils
.loadAnimation(this, R.anim.slide_right_in);
slideRightOut = AnimationUtils.loadAnimation(this,
R.anim.slide_right_out);
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
gestureDetector = new GestureDetector(this,
(OnGestureListener) gestureListener);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event))
return true;
else
return false;
}
}
GlobarVars.java:包 enn.ericsson.sitezoeker;
import android.app.Application;
import android.view.GestureDetector;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ViewFlipper;
public class GlobalVars extends Application {
private static GlobalVars vars;
public static GlobalVars getInstance() {
return vars;
}
@Override
public void onCreate() {
super.onCreate();
vars = this;
}
public static GestureDetector gestureDetector;
public static View.OnTouchListener gestureListener;
public static Animation slideLeftIn;
public static Animation slideLeftOut;
public static Animation slideRightIn;
public static Animation slideRightOut;
public static ViewFlipper viewFlipper;
}
MyGestureDetector 类:包 enn.ericsson.sitezoeker;
import android.view.MotionEvent;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.animation.Animation;
import android.widget.ViewFlipper;
class MyGestureDetector extends SimpleOnGestureListener {
ViewFlipper viewFlipper = GlobalVars.viewFlipper;
Animation slideLeftIn = GlobalVars.slideLeftIn;
Animation slideLeftOut = GlobalVars.slideLeftOut;
Animation slideRightIn = GlobalVars.slideRightIn;
Animation slideRightOut = GlobalVars.slideRightOut;
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
viewFlipper.setInAnimation(slideLeftIn);
viewFlipper.setOutAnimation(slideLeftOut);
viewFlipper.showNext();
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
viewFlipper.setInAnimation(slideRightIn);
viewFlipper.setOutAnimation(slideRightOut);
viewFlipper.showPrevious();
}
} catch (Exception e) {
// nothing
}
return false;
}
}
显现:
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:name=".GlobalVars"
package="enn.ericsson.sitezoeker"
android:installLocation="auto"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="me.user_interface.DisplayMessageActivity"/>
</application>
</manifest>
布局:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/View1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="false" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Provider:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="@+id/rbKPN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="KPN" />
<RadioButton
android:id="@+id/rbTMobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="T-Mobile" />
<RadioButton
android:id="@+id/rbVodafone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vodafone" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Site number:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/txtSitenr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:layout_width="match_parent"
android:layout_height="10dp" >
</TableRow>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="80dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView3"
android:layout_width="72dp"
android:layout_height="wrap_content"
android:text="Address:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/lblAddress"
android:layout_width="231dp"
android:layout_height="71dp"
android:background="@drawable/draw"
android:inputType="none"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:layout_width="match_parent"
android:layout_height="10dp" >
</TableRow>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView4"
android:layout_width="72dp"
android:layout_height="wrap_content"
android:text="City:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/lblCity"
android:layout_width="231dp"
android:layout_height="71dp"
android:background="@drawable/draw"
android:inputType="none"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="false"
android:id="@+id/View2" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="80dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView31"
android:layout_width="72dp"
android:layout_height="wrap_content"
android:text="Site name:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/lblSiteName"
android:layout_width="231dp"
android:layout_height="71dp"
android:background="@drawable/draw"
android:inputType="none"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:layout_width="match_parent"
android:layout_height="10dp" >
</TableRow>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView41"
android:layout_width="72dp"
android:layout_height="wrap_content"
android:text="Site type:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/lblSiteType"
android:layout_width="231dp"
android:layout_height="71dp"
android:background="@drawable/draw"
android:inputType="none"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:layout_width="match_parent"
android:layout_height="10dp" >
</TableRow>
</LinearLayout>
</LinearLayout>
</ScrollView>
</ViewFlipper>
rg,埃里克