2012-11-06 2 views
0

내 응용 프로그램 잘 처음 몇 번 실행하고 그만하기로 결정했다 내가 그것을 해결할 수 있는지 확인하기 위해 다음과 같은 방법을 시도했지만 아무 소용 "예기치 않게."오류 : "응용 프로그램이 예기치 않게 중지되었습니다. 다시 시도하십시오. '

  1. 이클립스 내에서 ADB를 다시 시작 (창>보기 표시> 장치를 사용하여).
  2. 이클립스 닫기, 수동으로 다시 시작 후 ADB 죽이고.
  3. 설치된 응용 프로그램을 제거하고 다시 설치.

나는 시간, 이클립스의 절반을 통지 항상 매달린 것 같다. 몇 가지 단절 문제로 홈을 시작하려고하는데 (왜 이렇게 계속해서 악화 되는가?), 그래서 나는 항상 Run을 다시 시작하고 다른 에뮬레이터를 시작합니다 (아래의 Console 대화 상자 참조).

[2012-11-06 11:58:03 - CostALoad] ------------------------------ 
[2012-11-06 11:58:03 - CostALoad] Android Launch! 
[2012-11-06 11:58:03 - CostALoad] adb is running normally. 
[2012-11-06 11:58:03 - CostALoad] Performing com.example.costaload.MainActivity activity launch 
[2012-11-06 11:58:04 - CostALoad] Automatic Target Mode: launching new emulator with compatible AVD 'myavd' 
[2012-11-06 11:58:04 - CostALoad] Launching a new emulator with Virtual Device 'myavd' 
[2012-11-06 11:58:06 - CostALoad] New emulator found: emulator-5554 
[2012-11-06 11:58:06 - CostALoad] Waiting for HOME ('android.process.acore') to be launched... 
[2012-11-06 11:58:40 - CostALoad] HOME is up on device 'emulator-5554' 
[2012-11-06 11:58:40 - CostALoad] Uploading CostALoad.apk onto device 'emulator-5554' 
[2012-11-06 11:58:42 - CostALoad] Installing CostALoad.apk... 
[2012-11-06 11:59:01 - CostALoad] Success! 
[2012-11-06 11:59:02 - CostALoad] Starting activity com.example.costaload.MainActivity on device 
    emulator- 5554 
[2012-11-06 11:59:04 - CostALoad] ActivityManager: Starting: Intent { act=android.intent.action.MAIN 
    cat=[android.intent.category.LAUNCHER] cmp=com.example.costaload/.MainActivity } 
[2012-11-06 12:17:00 - CostALoad] ------------------------------ 
[2012-11-06 12:17:00 - CostALoad] Android Launch! 
[2012-11-06 12:17:00 - CostALoad] adb is running normally. 
[2012-11-06 12:17:00 - CostALoad] Performing com.example.costaload.MainActivity activity launch 
[2012-11-06 12:17:01 - CostALoad] Automatic Target Mode: launching new emulator with compatible AVD 'myavd' 
[2012-11-06 12:17:01 - CostALoad] Launching a new emulator with Virtual Device 'myavd' 
[2012-11-06 12:17:25 - CostALoad] New emulator found: emulator-5554 
[2012-11-06 12:17:25 - CostALoad] Waiting for HOME ('android.process.acore') to be launched... 
[2012-11-06 12:18:43 - CostALoad] emulator-5554 disconnected! Cancelling 'com.example.costaload.MainActivity 
    activity launch'! 
[2012-11-06 12:20:07 - CostALoad] ------------------------------ 
[2012-11-06 12:20:07 - CostALoad] Android Launch! 
[2012-11-06 12:20:07 - CostALoad] adb is running normally. 
[2012-11-06 12:20:07 - CostALoad] Performing com.example.costaload.MainActivity activity launch 
[2012-11-06 12:20:07 - CostALoad] Automatic Target Mode: launching new emulator with compatible AVD 'myavd' 
[2012-11-06 12:20:07 - CostALoad] Launching a new emulator with Virtual Device 'myavd' 
[2012-11-06 12:20:22 - Emulator] WARNING: Data partition already in use. Changes will not persist! 
[2012-11-06 12:20:22 - Emulator] WARNING: Cache partition already in use. Changes will not persist! 
[2012-11-06 12:20:23 - CostALoad] New emulator found: emulator-5556 
[2012-11-06 12:20:23 - CostALoad] Waiting for HOME ('android.process.acore') to be launched... 
[2012-11-06 12:22:07 - CostALoad] HOME is up on device 'emulator-5556' 
[2012-11-06 12:22:07 - CostALoad] Uploading CostALoad.apk onto device 'emulator-5556' 
[2012-11-06 12:22:08 - CostALoad] Installing CostALoad.apk... 
[2012-11-06 12:22:26 - CostALoad] Success! 
[2012-11-06 12:22:27 - CostALoad] Starting activity com.example.costaload.MainActivity on device 
    emulator-5556 
[2012-11-06 12:22:31 - CostALoad] ActivityManager: Starting: Intent { act=android.intent.action.MAIN 
    cat=[android.intent.category.LAUNCHER] cmp=com.example.costaload/.MainActivity } 

그래서 RUN을 클릭 한 다음 5556을 시작하고 업로드 한 다음 중지했습니다. 이것은 아침 내내 계속되고 있으며 위에서 설명한 단계 중 어느 것도 문제를 멈추게하지는 않았습니다.

내가 LOGCAT을 볼 때, 나는 내가 초심자 인 것처럼 식별 할 수없는 것들이 있기 때문에 알아 내려고하지 않는다는 것을 인정한다. (예 : "zygote"??, looper, etc.). 즉, 코드가 처음 몇 번 제대로 작동하는지 이해할 수 없어서 현재 아래 로그에 표시된 내용을 던지고 있습니다. 내가 아는 유일한 것은 안드로이드 버튼 위젯이며 일종의 캐스트 예외입니다. 이상한 것은 버튼 리스너와 케이스 구조이기 때문에 어떤 버튼을 눌렀는지들을 수 있습니다. 그 외에, 나는 모른다. 줄 번호는 내가 알지도 못하는 파일들을위한 것이다. 내가 오류를 해석하는 생각으로

11-06 12:22:33.080: D/ddm-heap(223): Got feature list request 
11-06 12:22:34.350: D/AndroidRuntime(223): Shutting down VM 
11-06 12:22:34.350: W/dalvikvm(223): threadid=3: thread exiting with uncaught exception (group=0x4001b188) 
11-06 12:22:34.359: E/AndroidRuntime(223): Uncaught handler: thread main exiting due to uncaught exception 
11-06 12:22:34.369: E/AndroidRuntime(223): java.lang.RuntimeException: Unable to start activity 
    ComponentInfo{com.example.costaload/com.example.costaload.MainActivity}: java.lang.ClassCastException: 
    android.widget.Button 
11-06 12:22:34.369: E/AndroidRuntime(223): at android.app.ActivityThread.performLaunchActivity 
    (ActivityThread.java:2496) 
11-06 12:22:34.369: E/AndroidRuntime(223): at android.app.ActivityThread.handleLaunchActivity 
    (ActivityThread.java:2512) 
11-06 12:22:34.369: E/AndroidRuntime(223): at android.app.ActivityThread.access$2200 
    (ActivityThread.java:119) 
11-06 12:22:34.369: E/AndroidRuntime(223): at android.app.ActivityThread$H.handleMessage 
    (ActivityThread.java:1863) 
11-06 12:22:34.369: E/AndroidRuntime(223): at android.os.Handler.dispatchMessage(Handler.java:99) 
11-06 12:22:34.369: E/AndroidRuntime(223):  at android.os.Looper.loop(Looper.java:123) 
11-06 12:22:34.369: E/AndroidRuntime(223): at android.app.ActivityThread.main(ActivityThread.java:4363) 
11-06 12:22:34.369: E/AndroidRuntime(223):  at java.lang.reflect.Method.invokeNative(Native Method) 
11-06 12:22:34.369: E/AndroidRuntime(223):  at java.lang.reflect.Method.invoke(Method.java:521) 
11-06 12:22:34.369: E/AndroidRuntime(223): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run 
    (ZygoteInit.java:860) 
11-06 12:22:34.369: E/AndroidRuntime(223): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
11-06 12:22:34.369: E/AndroidRuntime(223): at dalvik.system.NativeStart.main(Native Method) 
11-06 12:22:34.369: E/AndroidRuntime(223): Caused by: java.lang.ClassCastException: android.widget.Button 
11-06 12:22:34.369: E/AndroidRuntime(223): at com.example.costaload.MainActivity.onCreate 
    (MainActivity.java:28) 
11-06 12:22:34.369: E/AndroidRuntime(223): at android.app.Instrumentation.callActivityOnCreate 
    (Instrumentation.java:1047) 
11-06 12:22:34.369: E/AndroidRuntime(223): at android.app.ActivityThread.performLaunchActivity 
    (ActivityThread.java:2459) 
11-06 12:22:34.369: E/AndroidRuntime(223):  ... 11 more 
11-06 12:22:34.419: I/dalvikvm(223): threadid=7: reacting to signal 3 
11-06 12:22:34.419: E/dalvikvm(223): Unable to open stack trace file '/data/anr/traces.txt': 
    Permission denied 
11-06 12:27:34.529: I/Process(223): Sending signal. PID: 223 SIG: 9 

시도는, 내가 가지고있는 추측은 버튼 위젯 함께 할 수있는 뭔가가 있다는 것입니다 그것은 자바 자체 때문에 무언가의 급강하를 복용처럼 나머지 보인다. LOGCAT은 내가 무엇인지 알지 못했거나 결코 만진 적이없는 것을 참조합니다. 이 모든 일이 일어나지 않게하려면 어떻게해야합니까? 여기

package com.example.costaload; 

import java.text.DecimalFormat; 
import java.text.NumberFormat; 

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


public class MainActivity extends Activity { 
EditText mile,diesel; 
Button button1, button2; 
TextView tv, tv2, tv3; 
private double x, y, z, costper, gallon, litres, ophours, stopdrive; 
CheckBox checkBox1, checkBox2, checkBox3, checkBox4; 
NumberFormat format = NumberFormat.getCurrencyInstance(); 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    mile= (EditText) findViewById(R.id.mile); 
    checkBox1 = (CheckBox) findViewById(R.id.checkBox1); 
    checkBox2 = (CheckBox) findViewById(R.id.checkBox2); 
    checkBox3 = (CheckBox) findViewById(R.id.checkBox3); 
    checkBox4 = (CheckBox) findViewById(R.id.checkBox4);   
    button1 = (Button) findViewById(R.id.button1); 
    button2 = (Button) findViewById(R.id.button2); 
    button1.setOnClickListener(onClickListener); 
    button2.setOnClickListener(onClickListener); 
    tv = (TextView) findViewById(R.id.cost); 
    tv2 = (TextView) findViewById(R.id.cpm); 
    tv3 = (TextView) findViewById(R.id.gallons); 
    diesel= (EditText) findViewById(R.id.diesel); 
     } 

private OnClickListener onClickListener = new OnClickListener() { 
    @Override 
    public void onClick(final View v) { 
     switch(v.getId()){ 
     case R.id.button1: 
      x=Double.parseDouble(mile.getText().toString()); 
      y=Double.parseDouble(diesel.getText().toString()); 
      if (checkBox2.isChecked()) { 
       x=x*2; 
      } 
      if (checkBox1.isChecked()) { 
       x=x*0.62137; 
      } 
      ophours = 0; 
      ophours = (x/55)+2; 
      if (ophours>=11){ 
       stopdrive = (ophours/10)-1; 
       if (stopdrive>1){ 
        ophours = ophours + (stopdrive*10); 
      } 
      gallon = x/5.5; 
      if (checkBox4.isChecked()) { 
       gallon = gallon + (ophours*1.1); 
      } 
      if (checkBox3.isChecked()) { 
       litres = gallon*3.785; 
       tv3.setText(new DecimalFormat("####.##").format(litres)+"L"); 
      } 
      z=(gallon*y)+(x*0.655); 
      costper=z/x; 
      tv.setText(format.format(z)); 
      tv2.setText(format.format(costper)+"/mile"); 
      tv3.setText(new DecimalFormat("####.##").format(gallon)+"gal."); 
     break;} 
     case R.id.button2: 
      Intent browserIntent = 
      new Intent(Intent.ACTION_VIEW, Url.parse("http://www.ratenroll.com")); 
           startActivity(browserIntent); 
     break; 
    } 
    }; 
    }; 
}      

가 있습니다 : 내가 말했듯이, 그것은 전에 실행했고 지금은 문제가 무엇인지 볼 수 없습니다 또는 내 프로젝트 파일에 뭔가가 있다면 그것을 일으키는 원인이되는, 내 코드 아래에 포함하고있다 주요 활동에 대한 XML은 모든 단추가 단추이기 때문에 난처한 상태입니다.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:text="# of miles" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/textView1" 
    android:layout_marginTop="40dp" 
    android:text="Price of diesel" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<EditText 
    android:id="@+id/diesel" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/textView2" 
    android:layout_alignBottom="@+id/textView2" 
    android:layout_alignLeft="@+id/mile" 
    android:layout_alignParentRight="true" 
    android:ems="10" 
    android:inputType="numberDecimal" /> 

<EditText 
    android:id="@+id/mile" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:layout_toRightOf="@+id/checkBox3" 
    android:ems="10" 
    android:inputType="numberDecimal" > 

    <requestFocus /> 
    </EditText> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:text="Visit www.ratenroll.com" /> 

<CheckBox 
    android:id="@+id/checkBox1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/diesel" 
    android:layout_marginTop="14dp" 
    android:text="Kilometres (not miles)" /> 

<CheckBox 
    android:id="@+id/checkBox2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/checkBox1" 
    android:layout_alignBottom="@+id/checkBox1" 
    android:layout_alignParentRight="true" 
    android:text="Round trip" /> 

<CheckBox 
    android:id="@+id/checkBox3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/checkBox1" 
    android:text="Litres (not gallons)" /> 

<CheckBox 
    android:id="@+id/checkBox4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/checkBox3" 
    android:layout_alignBottom="@+id/checkBox3" 
    android:layout_alignParentRight="true" 
    android:text="Reefer load" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/checkBox3" 
    android:layout_marginTop="50dp" 
    android:layout_toRightOf="@+id/textView2" 
    android:text="Compute" /> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/button1" 
    android:layout_marginTop="26dp" 
    android:text="Total Cost" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/textView4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/textView3" 
    android:text="Cost per mile" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/cost" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/textView4" 
    android:layout_alignParentRight="true" 
    android:text=" " 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/cpm" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/textView4" 
    android:layout_alignBottom="@+id/textView4" 
    android:layout_alignParentRight="true" 
    android:text=" " 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/textView5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignRight="@+id/textView4" 
    android:layout_below="@+id/textView4" 
    android:text="Fuel required" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <TextView 
    android:id="@+id/gallons" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/textView5" 
    android:layout_alignBottom="@+id/textView5" 
    android:layout_alignParentRight="true" 
    android:text=" " 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

</RelativeLayout> 

감사합니다.

+1

button1과 button2가 실제로 레이아웃 xml 파일의 버튼인지 확인하십시오. 예외는 하나의 클래스에서 다른 클래스 (예 : EditText)로 캐스팅을 시도하는 것을 의미합니다. 호환되는 유형이 아닌 – dymmeh

+0

버튼 중 하나는 실제로 버튼이 아닙니다. MainActivity.java 행을 참조하십시오. 28 범인의 경우 – petey

+0

28 번 라인에서는 실제로는 버튼이 아닌 ID를 참조합니다. – sabadow

답변

2

직접 Caused by:

로 시작하는 줄 다음에 로그 캣 라인을보고 오류를 일으키는 라인을 찾을 수는 기본적으로 형식은 다음과 같습니다 당신을 위해 그래서

Caused by: (error type) 
at:problematic method:line number 

응답 거짓말 여기 :

11-06 12:22:34.369: E/AndroidRuntime(223): Caused by: java.lang.ClassCastException: android.widget.Button 
11-06 12:22:34.369: E/AndroidRuntime(223): at com.example.costaload.MainActivity.onCreate (MainActivity.java:28) 

MainActivity 클래스에서 onCreate 메서드의 28 번째 줄이 문제입니다.

checkBox1 = (CheckBox) findViewById(R.id.checkBox1); 

클래스 캐스트 예외가 발생 했습니까? 확인한 해당보기는 CheckBox가 아닙니다.

MainActivity가 (사용중인) R 클래스를 가져 오지 못하는 것 같습니다. 나는 이클립스의 어떤 버전을 가지고 있는지, 또는 어떤 이상한 방식으로 이것을 처리하는지 모르겠다. 그러나 원하지 않는 어떤 값을 기본값으로 사용하고 있을지 모른다. 다른 수입과 코드의 상단에

넣어이

import com.example.costaload.R; 

또 다른 일이 당신의 의도가 있지만 switch 문에서 첫 번째 casebreak; 명령이 내부의 경우 잘 모르겠어요 if 블록 ophours이 11보다 작 으면 switch 문은 다음 사례로 넘어갑니다.

+1

제공된 정보를 통해 나는 동의합니다. OP의 XML은 아마도 '가 아닌'

+0

CheckBox1이 기본 XML에서와 같이 표시됩니다. Shawner

+0

질문에 XML 파일을 게시하십시오. – GraphicsMuncher

0

본질적으로 "버튼"중 하나 (실제로는)가 실제로 버튼이 아니므로 button1과 button2가 layout.xml 파일의 사실 버튼인지 확인하십시오. TextView를 버튼에 캐스트 할 수는 없습니다.

+0

button1과 button2는 모두 레이아웃 파일의 버튼입니다. – Shawner

0

activity_main 레이아웃에서 button1 및 button2 요소에 Button 유형이 있는지 확인 했습니까? 그렇다면 ADT가 R 파일을 다시 작성하도록 프로젝트를 정리하십시오.

이러한 종류의 문제는 Android 프로그래밍 학습을 시작할 때 (예 : 매니페스트 변경을 잊어 버리는 경우 등) 자주 발생합니다.

+0

예, 기본 레이아웃에는 모든 버튼과 체크 박스 ID가 있고 적절한 유형이 있습니다. – Shawner

+0

프로젝트를 청소했지만 여전히 오류가 발생합니다. : / – Shawner

관련 문제