1

最近、APIバージョン16(4.1)でAndroid開発を開始しました。developer.android.comで利用できるチュートリアルによると、私はインテントの使用法を教えてくれるアプリの開発を始めました。問題は、アプリがエミュレーターに読み込まれるとすぐに、アプリをシャットダウンする必要があるというエラーが表示されることです。私は自分のxmlコードを与えています。誰かが私がどこで間違っているのか教えてもらえますか?ありがとう。

<LinearLayout 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" 
android:orientation="horizontal">


<EditText
    android:id="@+id/et1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:hint="Edit text"
    android:layout_weight="1"
    tools:ignore="HardcodedText" />

<Button
    android:id="@+id/b1"
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:text="Press"
    android:onClick="sendMessage"
    tools:ignore="HardcodedText" />

</LinearLayout>

logcatを以下に示します。

09-26 19:35:03.880: E/Trace(615): error opening trace file: No such file or directory     (2)
09-26 19:35:04.430: D/AndroidRuntime(615): Shutting down VM
09-26 19:35:04.430: W/dalvikvm(615): threadid=1: thread exiting with uncaught exception  (group=0x40a13300)
09-26 19:35:04.471: E/AndroidRuntime(615): FATAL EXCEPTION: main
09-26 19:35:04.471: E/AndroidRuntime(615): java.lang.RuntimeException: Unable to     instantiate activity ComponentInfo{com.learn.training1/com.learn.training1.Training1}:     java.lang.NullPointerException
 09-26 19:35:04.471: E/AndroidRuntime(615):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
09-26 19:35:04.471: E/AndroidRuntime(615):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-26 19:35:04.471: E/AndroidRuntime(615):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-26 19:35:04.471: E/AndroidRuntime(615):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-26 19:35:04.471: E/AndroidRuntime(615):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 19:35:04.471: E/AndroidRuntime(615):  at android.os.Looper.loop(Looper.java:137)
09-26 19:35:04.471: E/AndroidRuntime(615):  at android.app.ActivityThread.main(ActivityThread.java:4745)
09-26 19:35:04.471: E/AndroidRuntime(615):  at java.lang.reflect.Method.invokeNative(Native Method)
09-26 19:35:04.471: E/AndroidRuntime(615):  at java.lang.reflect.Method.invoke(Method.java:511)
09-26 19:35:04.471: E/AndroidRuntime(615):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-26 19:35:04.471: E/AndroidRuntime(615):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-26 19:35:04.471: E/AndroidRuntime(615):  at dalvik.system.NativeStart.main(Native Method)
09-26 19:35:04.471: E/AndroidRuntime(615): Caused by: java.lang.NullPointerException
09-26 19:35:04.471: E/AndroidRuntime(615):  at android.app.Activity.findViewById(Activity.java:1825)
09-26 19:35:04.471: E/AndroidRuntime(615):  at com.learn.training1.Training1.<init>(Training1.java:15)
09-26 19:35:04.471: E/AndroidRuntime(615):  at java.lang.Class.newInstanceImpl(Native Method)
09-26 19:35:04.471: E/AndroidRuntime(615):  at java.lang.Class.newInstance(Class.java:1319)
09-26 19:35:04.471: E/AndroidRuntime(615):  at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
09-26 19:35:04.471: E/AndroidRuntime(615):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
09-26 19:35:04.471: E/AndroidRuntime(615):  ... 11 more
09-26 19:35:32.352: I/Process(615): Sending signal. PID: 615 SIG: 9
09-26 19:39:22.460: E/Trace(664): error opening trace file: No such file or directory (2)
09-26 19:39:22.820: D/AndroidRuntime(664): Shutting down VM
09-26 19:39:22.820: W/dalvikvm(664): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
09-26 19:39:22.846: E/AndroidRuntime(664): FATAL EXCEPTION: main
09-26 19:39:22.846: E/AndroidRuntime(664): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.learn.training1/com.learn.training1.Training1}: java.lang.NullPointerException
 09-26 19:39:22.846: E/AndroidRuntime(664):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
09-26 19:39:22.846: E/AndroidRuntime(664):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-26 19:39:22.846: E/AndroidRuntime(664):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-26 19:39:22.846: E/AndroidRuntime(664):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-26 19:39:22.846: E/AndroidRuntime(664):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 19:39:22.846: E/AndroidRuntime(664):  at android.os.Looper.loop(Looper.java:137)
09-26 19:39:22.846: E/AndroidRuntime(664):  at android.app.ActivityThread.main(ActivityThread.java:4745)
09-26 19:39:22.846: E/AndroidRuntime(664):  at java.lang.reflect.Method.invokeNative(Native Method)
09-26 19:39:22.846: E/AndroidRuntime(664):  at java.lang.reflect.Method.invoke(Method.java:511)
09-26 19:39:22.846: E/AndroidRuntime(664):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-26 19:39:22.846: E/AndroidRuntime(664):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-26 19:39:22.846: E/AndroidRuntime(664):  at dalvik.system.NativeStart.main(Native Method)
09-26 19:39:22.846: E/AndroidRuntime(664): Caused by: java.lang.NullPointerException
09-26 19:39:22.846: E/AndroidRuntime(664):  at android.app.Activity.findViewById(Activity.java:1825)
09-26 19:39:22.846: E/AndroidRuntime(664):  at com.learn.training1.Training1.<init>(Training1.java:15)
09-26 19:39:22.846: E/AndroidRuntime(664):  at java.lang.Class.newInstanceImpl(Native Method)
09-26 19:39:22.846: E/AndroidRuntime(664):  at java.lang.Class.newInstance(Class.java:1319)
09-26 19:39:22.846: E/AndroidRuntime(664):  at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
09-26 19:39:22.846: E/AndroidRuntime(664):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
09-26 19:39:22.846: E/AndroidRuntime(664):  ... 11 more
09-26 19:40:29.130: E/Trace(712): error opening trace file: No such file or directory (2)
09-26 19:40:29.431: D/dalvikvm(712): newInstance failed: Lcom/learn/training1/Training1; not accessible to Landroid/app/Instrumentation;
09-26 19:40:29.431: D/AndroidRuntime(712): Shutting down VM
09-26 19:40:29.431: W/dalvikvm(712): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
09-26 19:40:29.461: E/AndroidRuntime(712): FATAL EXCEPTION: main
09-26 19:40:29.461: E/AndroidRuntime(712): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.learn.training1/com.learn.training1.Training1}: java.lang.IllegalAccessException: access to class not allowed
09-26 19:40:29.461: E/AndroidRuntime(712):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
09-26 19:40:29.461: E/AndroidRuntime(712):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-26 19:40:29.461: E/AndroidRuntime(712):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-26 19:40:29.461: E/AndroidRuntime(712):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-26 19:40:29.461: E/AndroidRuntime(712):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 19:40:29.461: E/AndroidRuntime(712):  at android.os.Looper.loop(Looper.java:137)
09-26 19:40:29.461: E/AndroidRuntime(712):  at android.app.ActivityThread.main(ActivityThread.java:4745)
09-26 19:40:29.461: E/AndroidRuntime(712):  at java.lang.reflect.Method.invokeNative(Native Method)
09-26 19:40:29.461: E/AndroidRuntime(712):  at java.lang.reflect.Method.invoke(Method.java:511)
09-26 19:40:29.461: E/AndroidRuntime(712):  at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-26 19:40:29.461: E/AndroidRuntime(712):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-26 19:40:29.461: E/AndroidRuntime(712):  at dalvik.system.NativeStart.main(Native Method)
09-26 19:40:29.461: E/AndroidRuntime(712): Caused by: java.lang.IllegalAccessException: access to class not allowed
09-26 19:40:29.461: E/AndroidRuntime(712):  at java.lang.Class.newInstanceImpl(Native Method)
09-26 19:40:29.461: E/AndroidRuntime(712):  at java.lang.Class.newInstance(Class.java:1319)
09-26 19:40:29.461: E/AndroidRuntime(712):  at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
09-26 19:40:29.461: E/AndroidRuntime(712):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
09-26 19:40:29.461: E/AndroidRuntime(712):  ... 11 more
09-26 19:43:52.020: E/Trace(760): error opening trace file: No such file or directory (2)
09-26 19:43:52.110: D/dalvikvm(760): newInstance failed: Lcom/learn/training1/Training1; not accessible to Landroid/app/Instrumentation;
09-26 19:43:52.110: D/AndroidRuntime(760): Shutting down VM
09-26 19:43:52.110: W/dalvikvm(760): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
09-26 19:43:52.190: E/AndroidRuntime(760): FATAL EXCEPTION: main
09-26 19:43:52.190: E/AndroidRuntime(760): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.learn.training1/com.learn.training1.Training1}: java.lang.IllegalAccessException: access to class not allowed
09-26 19:43:52.190: E/AndroidRuntime(760):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
09-26 19:43:52.190: E/AndroidRuntime(760):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-26 19:43:52.190: E/AndroidRuntime(760):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-26 19:43:52.190: E/AndroidRuntime(760):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-26 19:43:52.190: E/AndroidRuntime(760):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 19:43:52.190: E/AndroidRuntime(760):  at android.os.Looper.loop(Looper.java:137)
09-26 19:43:52.190: E/AndroidRuntime(760):  at android.app.ActivityThread.main(ActivityThread.java:4745)
09-26 19:43:52.190: E/AndroidRuntime(760):  at java.lang.reflect.Method.invokeNative(Native Method)
 09-26 19:43:52.190: E/AndroidRuntime(760):     at java.lang.reflect.Method.invoke(Method.java:511)
09-26 19:43:52.190: E/AndroidRuntime(760):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-26 19:43:52.190: E/AndroidRuntime(760):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-26 19:43:52.190: E/AndroidRuntime(760):  at dalvik.system.NativeStart.main(Native Method)
09-26 19:43:52.190: E/AndroidRuntime(760): Caused by: java.lang.IllegalAccessException: access to class not allowed
09-26 19:43:52.190: E/AndroidRuntime(760):  at java.lang.Class.newInstanceImpl(Native Method)
09-26 19:43:52.190: E/AndroidRuntime(760):  at java.lang.Class.newInstance(Class.java:1319)
09-26 19:43:52.190: E/AndroidRuntime(760):  at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
09-26 19:43:52.190: E/AndroidRuntime(760):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
09-26 19:43:52.190: E/AndroidRuntime(760):  ... 11 more
09-26 19:47:20.550: I/Process(810): Sending signal. PID: 810 SIG: 9
4

1 に答える 1

1

あなたの活動が適切に宣言されていないようです(多分あなたはそれをしなかったのpublicですか?)。と呼ばれるファイルがTraining1.javaあり、このファイルには次のようなものがあります。

public class Training1 extends Activity {
    ...your activity code here...
}

https://groups.google.com/forum/?fromgroups=#!topic/android-developers/0Gw5WHc1J6gを参照してください

編集:メモを追加

注:また、コンストラクターは使用しないでください。Androidフレームワークがそれを処理します。

于 2012-09-26T15:38:00.207 に答える