0

这是我的第一个 android 应用程序,一个简单的应用程序,但每次启动它时它都会崩溃,而且我找不到问题,因为我还不了解大部分 java。

import android.app.Activity;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {

      public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);}

     public void calculate (View view) {
    EditText editText0= (EditText) findViewById(R.id.editText4);
    String m=editText0.getText().toString();
    char m1= m.charAt(0);
    char m2= m.charAt(2);
    double m1d =Double.valueOf(m1).doubleValue();
    double m2d =Double.valueOf(m2).doubleValue();
    double moa =m1d/m2d;
    EditText editText = (EditText) findViewById(R.id.editText1);
    double dist = Integer.parseInt(editText.getText().toString()); 
    EditText editText2 =(EditText) findViewById(R.id.editText2);
    double elev = Integer.parseInt(editText2.getText().toString());
    EditText editText3= (EditText) findViewById(R.id.editText3);
    double lat=Integer.parseInt(editText3.getText().toString()); 
    double clel = Math.round((Math.atan((elev/100)/dist))/(Math.atan((moa*0.0254)/91.44)));
    double cllat= Math.round((Math.atan((lat/100)/dist))/(Math.atan((moa*0.0254)/91.44)));
    TextView text1 = (TextView) findViewById(R.id.textView3);
    TextView text2 = (TextView) findViewById(R.id.textView4);
    String clels =new Double(clel).toString();
    String cllats = new Double(cllat).toString();
    text1.setText(clels);
    text2.setText(cllats);
}   
}

它不会在编辑器中给出错误。这是错误的 LogCat。

07-25 17:47:21.193: E/AndroidRuntime(2210): FATAL EXCEPTION: main
07-25 17:47:21.193: E/AndroidRuntime(2210): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.scope.fst/com.scope.fst.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.os.Looper.loop(Looper.java:137)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.app.ActivityThread.main(ActivityThread.java:5041)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at java.lang.reflect.Method.invokeNative(Native Method)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at java.lang.reflect.Method.invoke(Method.java:511)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at dalvik.system.NativeStart.main(Native Method)
07-25 17:47:21.193: E/AndroidRuntime(2210): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
07-25 17:47:21.193: E/AndroidRuntime(2210):     at  android.view.LayoutInflater.createView(LayoutInflater.java:613)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.app.Activity.setContentView(Activity.java:1881)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at com.scope.fst.MainActivity.onCreate(MainActivity.java:26)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.app.Activity.performCreate(Activity.java:5104)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-25 17:47:21.193: E/AndroidRuntime(2210):     ... 11 more
07-25 17:47:21.193: E/AndroidRuntime(2210): Caused by: java.lang.reflect.InvocationTargetException
07-25 17:47:21.193: E/AndroidRuntime(2210):     at java.lang.reflect.Constructor.constructNative(Native Method)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.view.LayoutInflater.createView(LayoutInflater.java:587)
07-25 17:47:21.193: E/AndroidRuntime(2210):     ... 23 more
07-25 17:47:21.193: E/AndroidRuntime(2210): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f070001 a=-1 r=0x7f070001}
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.content.res.Resources.loadDrawable(Resources.java:1927)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.view.View.<init>(View.java:3330)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.view.View.<init>(View.java:3259)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.view.ViewGroup.<init>(ViewGroup.java:425)
07-25 17:47:21.193: E/AndroidRuntime(2210):     at android.widget.RelativeLayout.<init>(RelativeLayout.java:210)
07-25 17:47:21.193: E/AndroidRuntime(2210):     ... 26 more

抱歉,如果解决方案真的很明显,但我找不到任何解决方案,所以我很感激任何帮助。先感谢您。

4

1 回答 1

0

您可能拥有activity_main.xml带有RelativeLayout的布局文件。

代码应该是这样的:

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width=   "fill_parent"      // some width 
    android:layout_height=  "wrap_content"     // some height
    android:background=     "@style/theme"     // background causing error

将其android:background从您的帐户中删除RelativeLayout并检查发生了什么。

于 2013-07-29T15:11:50.340 回答