私はprogrammigAndroidアプリを開始しました。しかし、私はこのフォーラムで似たようなものを見つけたにもかかわらず、これに苦労しています(ここで-まだチェックされています-)。ボタンを押すとアプリがクラッシュします。ここにコード:
package mobileapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View button = (Button) findViewById(R.id.button_print_string);
button.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.button_print_string:
EditText cerca = (EditText) findViewById(R.id.cerca);
Bundle bundle = new Bundle();
bundle.putString("result", cerca.getText().toString());
Intent Intent2 = new Intent(getApplicationContext(), SecondActivity.class);
startActivity(Intent2);
}
}
}
ここに私のmanifest_file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.stasbranger.clinigomobile"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity" >
<intent-filter ></intent-filter>
</activity>
</application>
</manifest>
と私のactivity_main:
<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" >
<Button
android:id="@+id/button_print_string"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="@string/str_button" />
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/cerca"
android:inputType="textEmailAddress"
android:text="@string/cerca">
<requestFocus></requestFocus>
</EditText>
</RelativeLayout>
私は得る:
08-01 09:40:59.335: E/AndroidRuntime(560): FATAL EXCEPTION: main
08-01 09:40:59.335: E/AndroidRuntime(560): java.lang.RuntimeException: Unable to start activity ComponentInfo{it.stasbranger.clinigomobile/it.stasbranger.clinigomobile.SecondActivity}: java.lang.NullPointerException
08-01 09:40:59.335: E/AndroidRuntime(560): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-01 09:40:59.335: E/AndroidRuntime(560): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-01 09:40:59.335: E/AndroidRuntime(560): at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-01 09:40:59.335: E/AndroidRuntime(560): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-01 09:40:59.335: E/AndroidRuntime(560): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 09:40:59.335: E/AndroidRuntime(560): at android.os.Looper.loop(Looper.java:137)
08-01 09:40:59.335: E/AndroidRuntime(560): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-01 09:40:59.335: E/AndroidRuntime(560): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 09:40:59.335: E/AndroidRuntime(560): at java.lang.reflect.Method.invoke(Method.java:511)
08-01 09:40:59.335: E/AndroidRuntime(560): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-01 09:40:59.335: E/AndroidRuntime(560): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-01 09:40:59.335: E/AndroidRuntime(560): at dalvik.system.NativeStart.main(Native Method)
08-01 09:40:59.335: E/AndroidRuntime(560): Caused by: java.lang.NullPointerException
08-01 09:40:59.335: E/AndroidRuntime(560): at it.stasbranger.clinigomobile.SecondActivity.onCreate(SecondActivity.java:14)
08-01 09:40:59.335: E/AndroidRuntime(560): at android.app.Activity.performCreate(Activity.java:4465)
08-01 09:40:59.335: E/AndroidRuntime(560): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-01 09:40:59.335: E/AndroidRuntime(560): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-01 09:40:59.335: E/AndroidRuntime(560): ... 11 more
提案?