Eclipse android应用程序在模拟器启动时崩溃

时间:2014-02-09 17:38:50

标签: java android eclipse

我是Android编程的新手,当我启动它时,我的应用程序崩溃了。

这个应用程序是餐馆的小费计算器,我不确定要包含什么,但从以前的帖子,这里是日志和Android清单。

02-09 12:28:50.640: D/AndroidRuntime(1282): Shutting down VM
02-09 12:28:50.640: W/dalvikvm(1282): threadid=1: thread exiting with uncaught exception (group=0xb3a55ba8)
02-09 12:28:50.670: E/AndroidRuntime(1282): FATAL EXCEPTION: main
02-09 12:28:50.670: E/AndroidRuntime(1282): Process: com.example.tipcalculator, PID: 1282
02-09 12:28:50.670: E/AndroidRuntime(1282): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.tipcalculator/com.example.tipcalculator.TipCalculator}: java.lang.ClassNotFoundException: Didn't find class "com.example.tipcalculator.TipCalculator" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
02-09 12:28:50.670: E/AndroidRuntime(1282):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at android.os.Looper.loop(Looper.java:136)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at android.app.ActivityThread.main(ActivityThread.java:5017)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at java.lang.reflect.Method.invokeNative(Native Method)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at java.lang.reflect.Method.invoke(Method.java:515)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at dalvik.system.NativeStart.main(Native Method)
02-09 12:28:50.670: E/AndroidRuntime(1282): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.tipcalculator.TipCalculator" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
02-09 12:28:50.670: E/AndroidRuntime(1282):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
02-09 12:28:50.670: E/AndroidRuntime(1282):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
02-09 12:28:50.670: E/AndroidRuntime(1282):     ... 11 more

并且Android清单是:          

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" android:persistent="false" android:hasCode="false">
        <activity
            android:name="com.example.tipcalculator.TipCalculator"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

和Java代码     package com.example.tipcalculator;

import java.text.DecimalFormat; 

import android.os.Bundle;
import android.app.Activity;
import android.view.KeyEvent;
import android.view.Menu;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class TipCalculator extends Activity {

// variables
private double billAmt;     //original bill amount
private double tipPerC;     //tip percent
private double total;       //final bill
private double tip;         //tip dollar value
//for printing values properly
private DecimalFormat df;
private String end;
// all of my elements used
private EditText _billAmt;
private EditText _tip;
private EditText _total;
private SeekBar _tipPerC;
private TextView _seekBarValue;

// initialize variables corresponding to Palette items
private void intitializeValues() {
    billAmt = total = tip = 0;
    tipPerC = 1500;
    // http://stackoverflow.com/questions/2538787/how-to-display-an-output-of-float-data-with-2-decimal-places-in-java
    df = new DecimalFormat("#.##");
    _billAmt = (EditText) findViewById(R.id.billAmt);
    _tip = (EditText) findViewById(R.id.tip);
    _total = (EditText) findViewById(R.id.total);
    _tipPerC = (SeekBar) findViewById(R.id.tipPerC);
    _seekBarValue = (TextView) findViewById(R.id.seekBarValue);
}

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

    // Initialize Values
    intitializeValues();

    // write functions for updating the SeekBar value as it is changed
    // http://stackoverflow.com/questions/19383246/set-custom-values-to-seek-bar
    _tipPerC.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        int progress = _tipPerC.getProgress();

        // update TextView and global variable "tipPerC" for later
        // calculations
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            _seekBarValue.setText(String.valueOf(progress));
            tipPerC = (double) progress;
        }

        // update TextView and global variable "tipPerC" for later
        // calculations
        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
            _seekBarValue.setText(String.valueOf(progress));
            tipPerC = (double) progress;
        }

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {
            // default code, do nothing
        }
    });

    //listener after Bill Amount has been entered or modified
    _billAmt.setOnEditorActionListener(new OnEditorActionListener() {                     
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // get value of float entry
            if (_billAmt.length() < 1) {
                Toast.makeText(getApplicationContext(), "Enter Amount", Toast.LENGTH_LONG).show();
            } else {
                billAmt = Double.parseDouble(_billAmt.getText().toString());
            }

            //calculations
            tip = billAmt * (tipPerC / 10000);
            total = billAmt + tip;

            // update views
            end = df.format(tip);
            _tip.setText(end);
            end = df.format(total);
            _total.setText(end);

            //default return?
            return false;
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.tip_calculator, menu);
        return true;
    }

}

如果还有什么我应该发布,或者我还有什么需要做的,请告诉我。谢谢大家的帮助。

0 个答案:

没有答案