Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.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运行时错误Eclipse_Java_Android_Eclipse - Fatal编程技术网

Java Android运行时错误Eclipse

Java Android运行时错误Eclipse,java,android,eclipse,Java,Android,Eclipse,我一直在通过阅读和尝试代码来学习一些java for android,每当我在android上启动应用程序时,它就会崩溃。在LogCat中,这显示: 2008-09 16:13:24.033:E/AndroidRuntime839:。。。还有11个 以下是我的活动_main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.c

我一直在通过阅读和尝试代码来学习一些java for android,每当我在android上启动应用程序时,它就会崩溃。在LogCat中,这显示:

2008-09 16:13:24.033:E/AndroidRuntime839:。。。还有11个

以下是我的活动_main.xml:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dip">
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textSize="20sp"
      android:text="Brews: " />
    <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="None"
      android:gravity="end"
      android:textSize="20sp"
      android:id="@+id/brew_count_label" />
  </LinearLayout>
  <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:gravity="center"
    android:padding="10dip">
    <Button
      android:id="@+id/brew_time_down"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="-"
      android:textSize="40sp" />
    <TextView
      android:id="@+id/brew_time"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="0:00"
      android:textSize="40sp"
      android:padding="10dip" />
    <Button
      android:id="@+id/brew_time_up"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="+"
      android:textSize="40sp" />
  </LinearLayout>
  <Button
    android:id="@+id/brew_start"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:text="Start" />
</LinearLayout>
下面是我的MainActivity.java:

package com.example.basketball;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity implements OnClickListener {
      /** Properties **/
      protected Button brewAddTime;
      protected Button brewDecreaseTime;
      protected Button startBrew;
      protected TextView brewCountLabel;
      protected TextView brewTimeLabel;

      protected int brewTime = 3;
      protected CountDownTimer brewCountDownTimer;
      protected int brewCount = 0;
      protected boolean isBrewing = false;

      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);

        // Connect interface elements to properties
        brewAddTime = (Button) findViewById(R.id.brew_time_up);
        brewDecreaseTime = (Button) findViewById(R.id.brew_time_down);
        startBrew = (Button) findViewById(R.id.brew_start);
        brewCountLabel = (TextView) findViewById(R.id.brew_count_label);
        brewTimeLabel = (TextView) findViewById(R.id.brew_time);

        // Setup ClickListeners
        brewAddTime.setOnClickListener(this);
        brewDecreaseTime.setOnClickListener(this);
        startBrew.setOnClickListener(this);

        // Set the initial brew values
        setBrewCount(0);
        setBrewTime(3);
      }

      /** Methods **/

      /**
       * Set an absolute value for the number of minutes to brew. Has no effect if a brew
       * is currently running.
       * @param minutes The number of minutes to brew.
       */
      public void setBrewTime(int minutes) {
        if(isBrewing)
          return;

        brewTime = minutes;

        if(brewTime < 1)
          brewTime = 1;

        brewTimeLabel.setText(String.valueOf(brewTime) + "m");
      }

      /**
       * Set the number of brews that have been made, and update the interface. 
       * @param count The new number of brews
       */
      public void setBrewCount(int count) {
        brewCount = count;
        brewCountLabel.setText(String.valueOf(brewCount));
      }

      /**
       * Start the brew timer
       */
      public void startBrew() {
        // Create a new CountDownTimer to track the brew time
        brewCountDownTimer = new CountDownTimer(brewTime * 60 * 1000, 1000) {
          @Override
          public void onTick(long millisUntilFinished) {
            brewTimeLabel.setText(String.valueOf(millisUntilFinished / 1000) + "s");
          }

          @Override
          public void onFinish() {
            isBrewing = false;
            setBrewCount(brewCount + 1);

            brewTimeLabel.setText("Brew Up!");
            startBrew.setText("Start");
          }
        };

        brewCountDownTimer.start();
        startBrew.setText("Stop");
        isBrewing = true;
      }

      /**
       * Stop the brew timer
       */
      public void stopBrew() {
        if(brewCountDownTimer != null)
          brewCountDownTimer.cancel();

        isBrewing = false;
        startBrew.setText("Start");
      }

      /** Interface Implementations **/
      /* (non-Javadoc)
       * @see android.view.View.OnClickListener#onClick(android.view.View)
       */
      public void onClick(View v) {
        if(v == brewAddTime)
          setBrewTime(brewTime + 1);
        else if(v == brewDecreaseTime)
          setBrewTime(brewTime -1);
        else if(v == startBrew) {
          if(isBrewing)
            stopBrew();
          else
            startBrew();
        }
      }
    }
有人知道如何修复这个错误吗? 请提供帮助。

请取消对setContentViewR.layout.main的注释;并将该行更改为setContentViewR.layout.activity_main;在


请完整发布日志您已注释掉setContentViewR.layout.main;在你的代码中。请取消那一行的注释。.发布完整的stacktracesorry,因为它是如此的无意义,但是stacktrace意味着什么?@jadbalout日志的异常部分做了,我得到了这个错误:main无法解析或者不是MainActivity字段。java/BasketBall/src/com/example/BasketBall line 28 javaProblem@jadbalout它应该是activity_main.xml。掌握教程
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);