これは私の最初の 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
解決策が本当に明白な場合は申し訳ありませんが、何も見つからなかったので、助けていただければ幸いです。前もって感謝します。