不幸的是#34; app"已停止在Android工作室

时间:2015-07-25 09:47:52

标签: java android android-studio

我刚接触Android并且我正在练习,当我完成这个练习应用程序时我跑了但是它说"不幸的是" app"已停止在android studio"问题出在哪儿?我并不认为XML文件存在问题。

我的mainactivity.java:

package designcoder.vivz.speechly;
import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.os.Handler;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;


public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener{

    private TextView mTextTime;
    private Handler handler;
    private long timeRemaning=5000;
    private ToggleButton toggleButton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTextTime = (TextView) findViewById(R.id.textView);
        AssetManager assetManager=getAssets();
        Typeface customFont=Typeface.createFromAsset(assetManager, "fonts/source_sans_pro_light.ttf");
        mTextTime.setTypeface(customFont);
        toggleButton= (ToggleButton) findViewById(R.id.toggleButton);
        toggleButton.setOnCheckedChangeListener(this);
        handler=new Handler();
        final Runnable runnable=new Runnable() {
            @Override
            public void run() {
              Log.d("VIVZ","run was called");
                timeRemaning=timeRemaning-1000;
                if(timeRemaning>0) {
                    handler.postDelayed(this, 1000);
                }
            }
        };


        handler.postDelayed(runnable,1000);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.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();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if(isChecked)
        {
            Toast.makeText(this,"ON",Toast.LENGTH_SHORT).show();
            AlertDialog.Builder builder=new AlertDialog.Builder(this);
            builder.setTitle("Please enter the time");
            builder.setView(R.layout.user_input);
            builder.show();
        }
        else
        {
            Toast.makeText(this,"OFF",Toast.LENGTH_SHORT).show();
        }
    }
}

0 个答案:

没有答案