Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android应用程序崩溃,由于倒计时?_Java_Android_Timer_Crash - Fatal编程技术网

Java Android应用程序崩溃,由于倒计时?

Java Android应用程序崩溃,由于倒计时?,java,android,timer,crash,Java,Android,Timer,Crash,我最近制作了一个应用程序,有一天我添加了一个倒计时计时器,并在这里和那里做了一些更改。现在,当我在我的(实际的)Galaxy Note 3上运行应用程序时,它会在我按下下面的播放按钮时崩溃。下面是我的LevelOne.java文件和MainActivity.java文件。顺便说一句,logcat没有显示任何东西,好像它没有意识到它崩溃了 LevelOne.java package com.parker.orangedot; import android.support.v7.app.Actio

我最近制作了一个应用程序,有一天我添加了一个倒计时计时器,并在这里和那里做了一些更改。现在,当我在我的(实际的)Galaxy Note 3上运行应用程序时,它会在我按下下面的播放按钮时崩溃。下面是我的LevelOne.java文件和MainActivity.java文件。顺便说一句,logcat没有显示任何东西,好像它没有意识到它崩溃了

LevelOne.java

package com.parker.orangedot;

import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

public class LevelOne extends ActionBarActivity {

    Button myButton;
    LevelOne context;
    CountDownTimer timer = new CountDownTimer(1500, 1500)
    {

        @Override
        public void onFinish() {
            Intent intent = new Intent(context, Scores.class);
            startActivity(intent);
        }

        @Override
        public void onTick(long arg0) {
            // TODO Auto-generated method stub

        }

    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        setContentView(R.layout.activity_level_one);

        //ass soon as this activity is created, I start my timer.
        timer.start();

        myButton = (Button) findViewById(R.id.button2);

        myButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {
                timer.cancel();
            }});
    }



    @Override
    public void onBackPressed() {
    }
    public void next(View view) {
        // Do something in response to button
        Intent intent = new Intent(this, LevelTwo.class);
        startActivity(intent);
    }
    public void openScores(View view) {
        // Do something in response to button
        Intent intent = new Intent(this, Scores.class);
        startActivity(intent);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.level_one, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_level_one,
                    container, false);
            return rootView;
        }
    }

}
MainActivity.java

package com.parker.orangedot;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }
    }

    public void openScores(View view) {
        // Do something in response to button
        Intent intent = new Intent(this, Scores.class);
        startActivity(intent);
    }
    public void play(View view) {
        // Do something in response to button
        Intent intent = new Intent(this, LevelOne.class);
        startActivity(intent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container,
                    false);
            return rootView;
        }
    }

}
更新:


在Galaxy Nexus上使用模拟器时,按“播放”键完全没有任何作用。

您是否在
AndroidManifest
中为
一级
添加了
活动
标记?请查看logcat
上下文
明显为空。替换为
LevelOne。此
。并修复你的日志,这里有一个例外。@adneal是的。(额外的文字,以便我可以发布此评论)