threadid=1: поток завершается с необработанным исключением (group=0x2eaa648)

Эта проблема возникла, и я не могу понять причину. (Журнал Cat Cat жирным шрифтом, обрезанный часть ошибки)

11-21 16: 48: 23.140: E / dalvikvm-heap (2364): Недостаточно памяти при выделении 42762316 байт.

11-21 16: 48: 23.200: D / skia (2364): --- декодер-> декодер вернул false

11-21 16: 48: 23.230: D / AndroidRuntime (2364): выключение виртуальной машины

11-21 16:48:23.230: W/dalvikvm(2364): threadid=1: поток завершается с необработанным исключением (group = 0xb2eaa648)

11-21 16: 48: 23.440: E / AndroidRuntime (2364): ИСКЛЮЧИТЕЛЬНОЕ ИСКЛЮЧЕНИЕ: основное

Соответствующий код (обрезанный): это страница MainActivity.java и работает нормально. при нажатии на вес (чтобы открыть EnterWeightActivityII.java) приложение останавливается

package my.app.cal;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @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;
    }

    public void mealclick(View v)
    {
        Intent i = new Intent(MainActivity.this,MealpageActivity.class);
        startActivityForResult(i,2);
    }
    public void WeightButtonHandler (View v) throws Exception{
        Intent intent = new Intent(MainActivity.this, EnterWeightActivityII.class);
        startActivity(intent);
    }

}

EnterWeightActivityII.java(проблема при нажатии на это действие)

package my.app.cal;

import java.text.DateFormat;
import java.util.Date;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class EnterWeightActivityII extends Activity {
    private Button saveButton;
    private Button showHistoryButton;
    private Button cancelButton;
    private EditText WeightEditText;
    private TextView DateTextViewii;
    private TextView weightTextView;
    private TextView averageTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.enter_weightii);

        setUpViews();

        //put today's date on the screen
        Date today = new Date();
        DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
        String cs = df.format(today); //cs means character sequence
        DateTextViewii.setText(cs);
                }

    /*
     Get the weight from the interface, validate the weight
    Create an object to hold the weight.
    */
    public void saveClickHandler(View v){
        String rawWeight;
        rawWeight = WeightEditText.getText().toString();
        double score = Double.parseDouble(rawWeight);

        if( isValid(score)){
            WeighingDetail weighingDetail;
            weighingDetail = new WeighingDetail(score, new Date());
            averageTextView.setText( "" + weighingDetail.calculateWeightAverage());


        }else{
            //pop up a dialog indicating that the data is invalid, will do it later
        }

    }


    private boolean isValid(double weight){
        if(weight > 0 && weight<=150)
            return true;
        return false;
    }
private void setUpViews(){
    saveButton = (Button) findViewById(R.id.saveButton);
    showHistoryButton = (Button) findViewById(R.id.showHistoryButton);
    cancelButton = (Button) findViewById(R.id.cancelButton);
    WeightEditText = (EditText) findViewById(R.id.WeightEditText);
    DateTextViewii = (TextView) findViewById(R.id.DateTextViewii);
    weightTextView = (TextView) findViewById(R.id.weightTextView);
    averageTextView = (TextView) findViewById(R.id.averageTextView);

}
}

WeighingDetail.java

package my.app.cal;

import java.text.DateFormat;
import java.util.Date;

public class WeighingDetail {

    private double weight;
    private Date date;

    public WeighingDetail(double weight, Date date) {
        this.weight = weight;
        this.date = date;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public double sumofWeight() {
        return weight;  //will make it right later when using sqlite.
    }

    public double calculateWeightAverage() {
        return sumofWeight() / 2;
    }

    public String toString() {
        String result;

        DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
        result = df.format(date) + " " + weight;
        return result;
    }
}

R.java

/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package my.app.cal;

public final class R {
    public static final class attr {
    }
    public static final class dimen {
        /**  Default screen margins, per the Android Design guidelines. 

         Customize dimensions originally defined in res/values/dimens.xml (such as
         screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.

         */
        public static final int activity_horizontal_margin=0x7f040000;
        public static final int activity_vertical_margin=0x7f040001;
    }
    public static final class drawable {
        public static final int ic_launcher=0x7f020000;
        public static final int weight=0x7f020001;
    }
    public static final class id {
        public static final int DateTextViewii=0x7f080004;
        public static final int Save=0x7f080002;
        public static final int Weight=0x7f080001;
        public static final int WeightEditText=0x7f080006;
        public static final int averageEditText=0x7f080008;
        public static final int averageTextView=0x7f080007;
        public static final int button2=0x7f080003;
        public static final int cancelButton=0x7f08000b;
        public static final int saveButton=0x7f080009;
        public static final int showHistoryButton=0x7f08000a;
        public static final int textView1=0x7f080000;
        public static final int weightTextView=0x7f080005;
    }
    public static final class layout {
        public static final int activity_main=0x7f030000;
        public static final int enter_meal=0x7f030001;
        public static final int enter_weightii=0x7f030002;
    }
    public static final class menu {
        public static final int breakfastpage=0x7f070000;
        public static final int main=0x7f070001;
        public static final int mealpage=0x7f070002;
    }
    public static final class string {
        public static final int _150=0x7f050010;
        public static final int action_settings=0x7f050001;
        public static final int addnewmeal=0x7f050006;
        public static final int app_name=0x7f050000;
        public static final int average_=0x7f05000c;
        public static final int cancel=0x7f05000f;
        public static final int date_of_the_weight=0x7f05000a;
        public static final int enter_weight_details=0x7f050009;
        public static final int exercise=0x7f050004;
        public static final int hello_world=0x7f050002;
        public static final int meal=0x7f050003;
        public static final int mealbutton=0x7f050011;
        public static final int my_weight_details=0x7f050008;
        public static final int save=0x7f05000d;
        public static final int show_history=0x7f05000e;
        public static final int title_activity_mealpage=0x7f050005;
        public static final int weighing_detail=0x7f050012;
        public static final int weight=0x7f050007;
        public static final int weight_=0x7f05000b;
    }
    public static final class style {
        /** 
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.


            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.


        Base application theme for API 11+. This theme completely replaces
        AppBaseTheme from res/values/styles.xml on API 11+ devices.

 API 11 theme customizations can go here. 

        Base application theme for API 14+. This theme completely replaces
        AppBaseTheme from BOTH res/values/styles.xml and
        res/values-v11/styles.xml on API 14+ devices.

 API 14 theme customizations can go here. 
         */
        public static final int AppBaseTheme=0x7f060000;
        /**  Application theme. 
 All customizations that are NOT specific to a particular API-level can go here. 
         */
        public static final int AppTheme=0x7f060001;
    }
}

файл манифеста (обрезанный)

  <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="my.app.cal.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="my.app.cal.MealpageActivity"
            android:label="@string/title_activity_mealpage" >
        </activity>
        <activity
            android:name="my.app.cal.WeightActivity"
            android:label="@string/my_weight_details" >
            </activity>
        <activity
            android:name="my.app.cal.EnterWeightActivityII"
            android:label="@string/enter_weight_details" >
        </activity>

    </application>

Пожалуйста, помогите понять, где я не прав. Замечания:

  1. Нет ошибок, исключение времени выполнения.
  2. Попробовал очистить проект.
  3. Я запутался, если я добавлю WeighingDetail.java в файл манифеста или нет. В примере, за которым я следовал, добавляются только действия.

0 ответов

Другие вопросы по тегам