Java 应用程序一直冻结,Android studio错误?
在这个应用程序中,我试图让一个小的Java 应用程序一直冻结,Android studio错误?,java,android,xml,android-studio,gestures,Java,Android,Xml,Android Studio,Gestures,在这个应用程序中,我试图让一个小的按钮在屏幕上移动,并让用户尝试避免屏幕上慢慢掉落的块 XML布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width=
按钮在屏幕上移动,并让用户尝试避免屏幕上慢慢掉落的块
XML布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="dev.kdeveloper.ballrun.MainActivity"
android:id="@+id/relativelayout">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ball"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="31dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="box1"
android:id="@+id/box1"
android:layout_alignParentTop="true"
android:layout_toStartOf="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="click to start"
android:id="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="98dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Game Over"
android:id="@+id/textView2"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
package dev.kdeveloper.ballrun;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.util.Random;
public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener,GestureDetector.OnDoubleTapListener{//i am using gestures in my application
GestureDetectorCompat gd;
public int location = 2;
ViewGroup vg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.gd = new GestureDetectorCompat(this,this);
final TextView tv = (TextView)findViewById(R.id.textView);
final TextView gameover = (TextView)findViewById(R.id.textView2);
final Animation blocksfall = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.blocksfall);
final Button b1 = (Button)findViewById(R.id.box1);
gameover.setVisibility(View.INVISIBLE);
tv.setVisibility(View.VISIBLE);
gd.setOnDoubleTapListener(this);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv.setVisibility(View.INVISIBLE);
mainloop(blocksfall, b1);
}
});
}public boolean continue1 = false;
private void mainloop(Animation blocksfall, Button b1) {
final Button ball = (Button)findViewById(R.id.ball);
Random rand = new Random();
int loopnum = 0;
boolean playerisplaying = true;
while(playerisplaying){
if(rand.nextInt(3)+1==1){
b1.setX(200);
}else if(rand.nextInt(3)+1==2){
b1.setX(400);
}else if(rand.nextInt(3)+1==3){
b1.setX(600);
}
loopnum+=1;
b1.startAnimation(blocksfall);
b1.setY(b1.getY()-400);
if(b1.getY()>ball.getY()+10){
if(b1.getX()==ball.getX()){
ball.setText("continue");
continue1 = false;
while(continue1==false){
ball.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
continue1 = true;
}
});
}
}
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
return false;
}
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
final Button ball = (Button)findViewById(R.id.ball);
Animation oneto2 = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.oneto2);
Animation threeto2 = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.threeto2);
Animation twoto3 = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.twoto3);
Animation twotoone = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.twoto1);
Animation onetoone = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.onetoone);
Animation threetothree = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.threetothree);
if(e.getX()>400){
if(location==2){
location = 3;
ball.startAnimation(twoto3);
ball.setX(600);
}else if(location==1){
location = 2;
ball.startAnimation(oneto2);
ball.setX(400);
}else if(location==3){
ball.startAnimation(threetothree);
location = 3;
ball.setX(600);
}
}else if(e.getX()<400){
if(location==2){
location = 1;
ball.startAnimation(twotoone);
ball.setX(200);
}else if(location==1){
ball.startAnimation(onetoone);
locat`enter code here`ion = 1;
ball.setX(200);
}else if(location==3){
ball.startAnimation(threeto2);
location = 2;
ball.setX(400);
}
}
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event){
this.gd.onTouchEvent(event);
return super.onTouchEvent(event);
}
}
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:duration="150"
android:toXDelta="100"
android:repeatCount="1"
android:repeatMode="reverse"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:duration="150"
android:toXDelta="-100"
android:repeatCount="1"
android:repeatMode="reverse"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="200"
android:fromXDelta="200"
android:toXDelta="0"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1000"
android:fromYDelta="400"
android:toYDelta="0"/>
</set>
> 01-23 20:20:28.892 31538-31544/dev.kdeveloper.ballrun I/art:
> Thread[2,tid=31544,WaitingInMainSignalCatcherLoop,Thread*=0xaf60e400,peer=0x12c8b080,"Signal
> Catcher"]: reacting to signal 3 01-23 20:20:29.342
> 31538-31544/dev.kdeveloper.ballrun I/art: Wrote stack traces to
> '/data/anr/traces.txt'
entire logcat:
01-23 20:19:54.552 31538-31538/? E/Zygote: MountEmulatedStorage()
01-23 20:19:54.552 31538-31538/? E/Zygote: v2
01-23 20:19:54.552 31538-31538/? I/libpersona: KNOX_SDCARD checking this for 10360
01-23 20:19:54.552 31538-31538/? I/libpersona: KNOX_SDCARD not a persona
01-23 20:19:54.572 31538-31538/? I/SELinux: Function: selinux_compare_spd_ram, SPD-policy is existed. and_ver=SEPF_SM-G900F_5.0 ver=27
01-23 20:19:54.572 31538-31538/? I/SELinux: Function: selinux_compare_spd_ram , priority [2] , priority version is VE=SEPF_SM-G900F_5.0-1_0032
01-23 20:19:54.572 31538-31538/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
01-23 20:19:54.572 31538-31538/? I/art: Late-enabling -Xcheck:jni
01-23 20:19:54.602 31538-31538/? D/TimaKeyStoreProvider: TimaSignature is unavailable
01-23 20:19:54.602 31538-31538/? D/ActivityThread: Added TimaKeyStore provider
01-23 20:19:54.642 31538-31538/dev.kdeveloper.ballrun D/ResourcesManager: creating new AssetManager and set to /data/app/dev.kdeveloper.ballrun-1/base.apk
01-23 20:19:54.852 31538-31538/dev.kdeveloper.ballrun V/BitmapFactory: DecodeImagePath(decodeResourceStream3) : res/drawable-xxhdpi-v4/abc_ic_ab_back_mtrl_am_alpha.png
01-23 20:19:54.892 31538-31538/dev.kdeveloper.ballrun D/Activity: performCreate Call secproduct feature valuefalse
01-23 20:19:54.892 31538-31538/dev.kdeveloper.ballrun D/Activity: performCreate Call debug elastic valuetrue
01-23 20:19:54.912 31538-31583/dev.kdeveloper.ballrun D/OpenGLRenderer: Render dirty regions requested: true
01-23 20:19:54.942 31538-31583/dev.kdeveloper.ballrun I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: ()
OpenGL ES Shader Compiler Version: E031.25.01.03
Build Date: 03/03/15 Tue
Local Branch: LA.BF.1.1_RB1_20150108_025_1077123_1158499
Remote Branch:
Local Patches:
Reconstruct Branch:
01-23 20:19:54.942 31538-31583/dev.kdeveloper.ballrun I/OpenGLRenderer: Initialized EGL, version 1.4
01-23 20:19:54.962 31538-31583/dev.kdeveloper.ballrun I/OpenGLRenderer: HWUI protection enabled for context , &this =0xaef22088 ,&mEglDisplay = 1 , &mEglConfig = 8
01-23 20:19:54.962 31538-31583/dev.kdeveloper.ballrun D/OpenGLRenderer: Enabling debug mode 0
01-23 20:19:55.122 31538-31538/dev.kdeveloper.ballrun I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@2bd9790c time:36886929
01-23 20:19:55.932 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:19:56.352 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:19:57.712 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:01.892 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:02.412 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:02.842 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:03.342 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:03.652 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:03.952 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:04.232 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:04.672 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:06.162 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:28.892 31538-31544/dev.kdeveloper.ballrun I/art: Thread[2,tid=31544,WaitingInMainSignalCatcherLoop,Thread*=0xaf60e400,peer=0x12c8b080,"Signal Catcher"]: reacting to signal 3
01-23 20:20:29.342 31538-31544/dev.kdeveloper.ballrun I/art: Wrote stack traces to '/data/anr/traces.txt'
01-23 20:23:28.322 31538-31545/dev.kdeveloper.ballrun W/art: Suspending all threads took: 5.108ms
01-23 20:26:47.482 31538-31545/dev.kdeveloper.ballrun W/art: Suspending all threads took: 7.433ms
Java类:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="dev.kdeveloper.ballrun.MainActivity"
android:id="@+id/relativelayout">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ball"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="31dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="box1"
android:id="@+id/box1"
android:layout_alignParentTop="true"
android:layout_toStartOf="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="click to start"
android:id="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="98dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Game Over"
android:id="@+id/textView2"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
package dev.kdeveloper.ballrun;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.util.Random;
public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener,GestureDetector.OnDoubleTapListener{//i am using gestures in my application
GestureDetectorCompat gd;
public int location = 2;
ViewGroup vg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.gd = new GestureDetectorCompat(this,this);
final TextView tv = (TextView)findViewById(R.id.textView);
final TextView gameover = (TextView)findViewById(R.id.textView2);
final Animation blocksfall = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.blocksfall);
final Button b1 = (Button)findViewById(R.id.box1);
gameover.setVisibility(View.INVISIBLE);
tv.setVisibility(View.VISIBLE);
gd.setOnDoubleTapListener(this);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv.setVisibility(View.INVISIBLE);
mainloop(blocksfall, b1);
}
});
}public boolean continue1 = false;
private void mainloop(Animation blocksfall, Button b1) {
final Button ball = (Button)findViewById(R.id.ball);
Random rand = new Random();
int loopnum = 0;
boolean playerisplaying = true;
while(playerisplaying){
if(rand.nextInt(3)+1==1){
b1.setX(200);
}else if(rand.nextInt(3)+1==2){
b1.setX(400);
}else if(rand.nextInt(3)+1==3){
b1.setX(600);
}
loopnum+=1;
b1.startAnimation(blocksfall);
b1.setY(b1.getY()-400);
if(b1.getY()>ball.getY()+10){
if(b1.getX()==ball.getX()){
ball.setText("continue");
continue1 = false;
while(continue1==false){
ball.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
continue1 = true;
}
});
}
}
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
return false;
}
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
final Button ball = (Button)findViewById(R.id.ball);
Animation oneto2 = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.oneto2);
Animation threeto2 = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.threeto2);
Animation twoto3 = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.twoto3);
Animation twotoone = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.twoto1);
Animation onetoone = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.onetoone);
Animation threetothree = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.threetothree);
if(e.getX()>400){
if(location==2){
location = 3;
ball.startAnimation(twoto3);
ball.setX(600);
}else if(location==1){
location = 2;
ball.startAnimation(oneto2);
ball.setX(400);
}else if(location==3){
ball.startAnimation(threetothree);
location = 3;
ball.setX(600);
}
}else if(e.getX()<400){
if(location==2){
location = 1;
ball.startAnimation(twotoone);
ball.setX(200);
}else if(location==1){
ball.startAnimation(onetoone);
locat`enter code here`ion = 1;
ball.setX(200);
}else if(location==3){
ball.startAnimation(threeto2);
location = 2;
ball.setX(400);
}
}
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event){
this.gd.onTouchEvent(event);
return super.onTouchEvent(event);
}
}
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:duration="150"
android:toXDelta="100"
android:repeatCount="1"
android:repeatMode="reverse"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:duration="150"
android:toXDelta="-100"
android:repeatCount="1"
android:repeatMode="reverse"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="200"
android:fromXDelta="200"
android:toXDelta="0"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1000"
android:fromYDelta="400"
android:toYDelta="0"/>
</set>
> 01-23 20:20:28.892 31538-31544/dev.kdeveloper.ballrun I/art:
> Thread[2,tid=31544,WaitingInMainSignalCatcherLoop,Thread*=0xaf60e400,peer=0x12c8b080,"Signal
> Catcher"]: reacting to signal 3 01-23 20:20:29.342
> 31538-31544/dev.kdeveloper.ballrun I/art: Wrote stack traces to
> '/data/anr/traces.txt'
entire logcat:
01-23 20:19:54.552 31538-31538/? E/Zygote: MountEmulatedStorage()
01-23 20:19:54.552 31538-31538/? E/Zygote: v2
01-23 20:19:54.552 31538-31538/? I/libpersona: KNOX_SDCARD checking this for 10360
01-23 20:19:54.552 31538-31538/? I/libpersona: KNOX_SDCARD not a persona
01-23 20:19:54.572 31538-31538/? I/SELinux: Function: selinux_compare_spd_ram, SPD-policy is existed. and_ver=SEPF_SM-G900F_5.0 ver=27
01-23 20:19:54.572 31538-31538/? I/SELinux: Function: selinux_compare_spd_ram , priority [2] , priority version is VE=SEPF_SM-G900F_5.0-1_0032
01-23 20:19:54.572 31538-31538/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
01-23 20:19:54.572 31538-31538/? I/art: Late-enabling -Xcheck:jni
01-23 20:19:54.602 31538-31538/? D/TimaKeyStoreProvider: TimaSignature is unavailable
01-23 20:19:54.602 31538-31538/? D/ActivityThread: Added TimaKeyStore provider
01-23 20:19:54.642 31538-31538/dev.kdeveloper.ballrun D/ResourcesManager: creating new AssetManager and set to /data/app/dev.kdeveloper.ballrun-1/base.apk
01-23 20:19:54.852 31538-31538/dev.kdeveloper.ballrun V/BitmapFactory: DecodeImagePath(decodeResourceStream3) : res/drawable-xxhdpi-v4/abc_ic_ab_back_mtrl_am_alpha.png
01-23 20:19:54.892 31538-31538/dev.kdeveloper.ballrun D/Activity: performCreate Call secproduct feature valuefalse
01-23 20:19:54.892 31538-31538/dev.kdeveloper.ballrun D/Activity: performCreate Call debug elastic valuetrue
01-23 20:19:54.912 31538-31583/dev.kdeveloper.ballrun D/OpenGLRenderer: Render dirty regions requested: true
01-23 20:19:54.942 31538-31583/dev.kdeveloper.ballrun I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: ()
OpenGL ES Shader Compiler Version: E031.25.01.03
Build Date: 03/03/15 Tue
Local Branch: LA.BF.1.1_RB1_20150108_025_1077123_1158499
Remote Branch:
Local Patches:
Reconstruct Branch:
01-23 20:19:54.942 31538-31583/dev.kdeveloper.ballrun I/OpenGLRenderer: Initialized EGL, version 1.4
01-23 20:19:54.962 31538-31583/dev.kdeveloper.ballrun I/OpenGLRenderer: HWUI protection enabled for context , &this =0xaef22088 ,&mEglDisplay = 1 , &mEglConfig = 8
01-23 20:19:54.962 31538-31583/dev.kdeveloper.ballrun D/OpenGLRenderer: Enabling debug mode 0
01-23 20:19:55.122 31538-31538/dev.kdeveloper.ballrun I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@2bd9790c time:36886929
01-23 20:19:55.932 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:19:56.352 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:19:57.712 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:01.892 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:02.412 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:02.842 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:03.342 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:03.652 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:03.952 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:04.232 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:04.672 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:06.162 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
01-23 20:20:28.892 31538-31544/dev.kdeveloper.ballrun I/art: Thread[2,tid=31544,WaitingInMainSignalCatcherLoop,Thread*=0xaf60e400,peer=0x12c8b080,"Signal Catcher"]: reacting to signal 3
01-23 20:20:29.342 31538-31544/dev.kdeveloper.ballrun I/art: Wrote stack traces to '/data/anr/traces.txt'
01-23 20:23:28.322 31538-31545/dev.kdeveloper.ballrun W/art: Suspending all threads took: 5.108ms
01-23 20:26:47.482 31538-31545/dev.kdeveloper.ballrun W/art: Suspending all threads took: 7.433ms
包dev.kdeveloper.ballrun;
导入android.support.v4.view.GestureDetectorCompat;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.view.GestureDetector;
导入android.view.MotionEvent;
导入android.view.view;
导入android.view.ViewGroup;
导入android.view.animation.animation;
导入android.view.animation.AnimationUtils;
导入android.widget.Button;
导入android.widget.TextView;
导入org.w3c.dom.Text;
导入java.util.Random;
公共类MainActivity扩展了AppCompatActivity实现了GestureDetector.OnGestureListener,GestureDetector.OnDoubletaListener{//我正在应用程序中使用手势
手势检测器;
公共int位置=2;
视图组vg;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.gd=新的GestureDetectorCompat(this,this);
最终文本视图tv=(文本视图)findViewById(R.id.TextView);
最终TextView gameover=(TextView)findViewById(R.id.textView2);
final Animation blocksfall=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.blocksfall);
最终按钮b1=(按钮)findViewById(R.id.box1);
gameover.setVisibility(View.INVISIBLE);
tv.setVisibility(View.VISIBLE);
gd.setOnDoubleTapListener(this);
tv.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
tv.setVisibility(视图.不可见);
主回路(blocksfall,b1);
}
});
}公共布尔continue1=false;
私有void主循环(动画块球,按钮b1){
最终按钮球=(按钮)findViewById(R.id.ball);
Random rand=新的Random();
int loopnum=0;
布尔playerSplaying=true;
while(playerSplaying){
if(rand.nextInt(3)+1==1){
b1.setX(200);
}else if(rand.nextInt(3)+1==2){
b1.setX(400);
}else if(rand.nextInt(3)+1==3){
b1.setX(600);
}
loopnum+=1;
b1.启动(块式足球);
b1.setY(b1.getY()-400);
如果(b1.getY()>ball.getY()+10){
如果(b1.getX()==ball.getX()){
ball.setText(“继续”);
continue1=假;
while(continue1==false){
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
continue1=真;
}
});
}
}
}
试一试{
睡眠(1000);
}捕捉(中断异常e){
e、 printStackTrace();
}
}
}
@凌驾
公共布尔值OnSingleTapConfiged(运动事件e){
返回false;
}
@凌驾
公共布尔onDoubleTap(运动事件e){
返回false;
}
@凌驾
公共布尔OnDoubleTapeEvent(运动事件e){
返回false;
}
@凌驾
公共布尔onDown(运动事件e){
返回false;
}
@凌驾
在ShowPress上公开作废(运动事件e){
}
@凌驾
公共布尔onSingleTapUp(运动事件e){
最终按钮球=(按钮)findViewById(R.id.ball);
Animation oneto2=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.oneto2);
Animation threeto2=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.threeto2);
Animation twoto3=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.twoto3);
动画twotoone=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.twoto1);
Animation onetoone=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.onetoone);
Animation threetothree=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.threetothree);
如果(如getX()>400){
如果(位置==2){
位置=3;
球。开始运动(2到3);
球.setX(600);
}else if(位置==1){
位置=2;
球。开始运动(oneto2);
球.setX(400);
}否则如果(位置==3){
球。开始运动(三对三);
位置=3;
球.setX(600);
}
}否则如果(e.getX()从不-从不-从不做
(一)
2) 进行while(true)
循环
3) 进行任何长时间/繁重的操作(如网络呼叫)
在UI线程中
此线程(也称为主线程)负责更新应用程序接口。系统定期检查线程是否能够响应。因此,如果线程无法响应(由于我上面提到的原因),ANR(应用程序未响应)出现异常。当应用程序冻结时,你能显示log cat的输出吗?我已经更新了它,包括日志。这是错误日志吗?我想这不是应用程序冻结的地方。我已经包括了logcat,这是应用程序冻结后出现的结果,否则它仍然会显示:01-23 20:19:57.712 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl:ViewPostImeInputStage ACTION_DOWN 01-23 20:20:01.892 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl:ViewPostImeInputStage ACTION_DOWN 01-23 20:20:02.412 31538-31538/dev.kdeveloper.ballrun D/ViewRootImpl:ViewPo