では動作しません。私はテントクラスでボタンをクリックすることにより、別のアクティビティを表示しようとしていますが、それはが自分のアプリケーション
を「残念ながら私のアプリケーションが停止しました」を与えるスティルスでエラーが
と私はコードは、これが
course=(EditText) findViewById(R.id.editText);
hour=(EditText) findViewById(R.id.editText1);
add= (Button) findViewById(R.id.button);
view_= (Button) findViewById(R.id.button1);
view_.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this,ViewActivity.class);
startActivity(intent);
}
});
}
}
`メインアクティビティクラスです
正しいだと思います
、これは私が
を.ViewActivityのAndroidManifest.xmlに<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ViewActivity" />
</application>'
locat >>
FATAL EXCEPTION: main
Process: com.example.android.intent, PID: 11316
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.intent/com.example.android.intent.ViewActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.android.intent.ViewActivity.onCreate(ViewActivity.java:34)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
ビューのレイアウトファイルを追加した追加で
TextView tv;
Button ed, de, view_;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
tv = (TextView) findViewById(R.id.details);
ed = (Button) findViewById(R.id.ed);
de = (Button) findViewById(R.id.delete);
view_= (Button) findViewById(R.id.button1);
Intent intent = getIntent();
view_.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
ViewActivityクラスです
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TableRow
android:layout_width="80dp"
android:layout_height="50dp" >
<TextView
android:text="Course"
android:layout_width="80dp"
android:layout_height="50dp"
android:id="@+id/course"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:textSize="24sp" />
<TextView
android:text="Hour"
android:layout_width="80dp"
android:layout_height="50dp"
android:id="@+id/hour"
android:layout_marginLeft="170dp"
android:layout_marginTop="10dp"
android:textSize="24sp"
android:layout_marginRight="30dp" />
</TableRow>
</TableLayout>
<Button
android:text="Edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="45dp"
android:id="@+id/ed"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="38dp"
android:layout_marginStart="38dp"
android:onClick="" />
<Button
android:text="Delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="19dp"
android:layout_marginEnd="19dp"
android:id="@+id/delete"
android:layout_alignBaseline="@+id/ed"
android:layout_alignBottom="@+id/ed"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:onClick="" />
<TextView
android:layout_width="350dp"
android:layout_height="350dp"
android:id="@+id/details"
android:layout_above="@+id/delete"
android:layout_centerHorizontal="true" />
<Button
android:text="Refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/delete"
android:layout_toLeftOf="@+id/delete"
android:layout_toStartOf="@+id/delete"
android:layout_marginRight="28dp"
android:layout_marginEnd="28dp"
android:id="@+id/button4"
android:onClick="" />
は感謝:)
あなたもlogcatを投稿してください。 – Lal
あなたの完全なAndroidManifestも投稿してください.. – Lal