こんにちは、Android の初心者で、デイリー プランナーのようなアプリを作りたいと思っています。問題はこれです。アプリが開き、新しいタスクボタンが表示されます。ボタンを押して新しいタスクを追加すると、アプリがクラッシュします。フォーラムで同様の問題を検索しましたが、助けが得られませんでした。
ここに私の猫のログファイルがあります:
09-27 19:03:46.035: D/dalvikvm(19346): Late-enabling CheckJNI
09-27 19:03:46.440: D/dalvikvm(19346): GC_FOR_ALLOC freed 136K, 4% free 12874K/13319K, paused 31ms
09-27 19:03:46.440: I/dalvikvm-heap(19346): Grow heap (frag case) to 13.127MB for 379472-byte allocation
09-27 19:03:46.465: D/dalvikvm(19346): GC_FOR_ALLOC freed 0K, 4% free 13245K/13703K, paused 20ms
09-27 19:03:46.535: D/AbsListView(19346): Get MotionRecognitionManager
09-27 19:03:49.510: D/CLIPBOARD(19346): Hide Clipboard dialog at Starting input: finished by someone else... !
09-27 19:03:53.625: D/AndroidRuntime(19346): Shutting down VM
09-27 19:03:53.625: W/dalvikvm(19346): threadid=1: thread exiting with uncaught exception (group=0x40c5d1f8)
09-27 19:03:53.635: E/AndroidRuntime(19346): FATAL EXCEPTION: main
09-27 19:03:53.635: E/AndroidRuntime(19346): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.dailyplanner/com.example.dailyplanner.new_task}: java.lang.NullPointerException
09-27 19:03:53.635: E/AndroidRuntime(19346): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1894)
09-27 19:03:53.635: E/AndroidRuntime(19346): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
09-27 19:03:53.635: E/AndroidRuntime(19346): at android.app.ActivityThread.access$600(ActivityThread.java:128)
09-27 19:03:53.635: E/AndroidRuntime(19346): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
09-27 19:03:53.635: E/AndroidRuntime(19346): at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 19:03:53.635: E/AndroidRuntime(19346): at android.os.Looper.loop(Looper.java:137)
09-27 19:03:53.635: E/AndroidRuntime(19346): at android.app.ActivityThread.main(ActivityThread.java:4514)
09-27 19:03:53.635: E/AndroidRuntime(19346): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 19:03:53.635: E/AndroidRuntime(19346): at java.lang.reflect.Method.invoke(Method.java:511)
09-27 19:03:53.635: E/AndroidRuntime(19346): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
09-27 19:03:53.635: E/AndroidRuntime(19346): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
09-27 19:03:53.635: E/AndroidRuntime(19346): at dalvik.system.NativeStart.main(Native Method)
09-27 19:03:53.635: E/AndroidRuntime(19346): Caused by: java.lang.NullPointerException
09-27 19:03:53.635: E/AndroidRuntime(19346): at android.app.Activity.findViewById(Activity.java:1851)
09-27 19:03:53.635: E/AndroidRuntime(19346): at com.example.dailyplanner.new_task.<init>(new_task.java:19)
09-27 19:03:53.635: E/AndroidRuntime(19346): at java.lang.Class.newInstanceImpl(Native Method)
09-27 19:03:53.635: E/AndroidRuntime(19346): at java.lang.Class.newInstance(Class.java:1319)
09-27 19:03:53.635: E/AndroidRuntime(19346): at android.app.Instrumentation.newActivity(Instrumentation.java:1027)
09-27 19:03:53.635: E/AndroidRuntime(19346): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1885)
09-27 19:03:53.635: E/AndroidRuntime(19346): ... 11 more
これはアンドロイドマニフェストです:
<manifest package="com.example.dailyplanner"
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1">
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".new_task"/>
</application>
ここに私のmain.javaファイルがあります:
package com.example.dailyplanner;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//SQLiteDatabase db = openOrCreateDatabase("MyDB", MODE_PRIVATE, null );
//db.execSQL("CREATE TABLE IF NOT EXISTS Data1 (Id INT IDENTITY(1,1) NOT NULL, text VARCHAR, time TIME, date DATE)");
Button nTaskBtn = (Button) findViewById(R.id.nTask);
nTaskBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent nTaskScreen = new Intent(getApplicationContext() , new_task.class);
startActivity(nTaskScreen);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
これは new_task.java ファイルです。
package com.example.dailyplanner;
import android.R.string;
import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.net.UrlQuerySanitizer.ValueSanitizer;
import android.os.Bundle;
import android.renderscript.Sampler.Value;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
public class new_task extends Activity {
static final int TIME_DIALOG_ID=0;
final TextView timeText = (TextView) findViewById(R.id.timeTxt);
TextView dateText = (TextView) findViewById(R.id.dateTxt);
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.new_task);
Button btnSave = (Button) findViewById(R.id.btnSave);
btnSave.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
}
});
Button btnSetTime = (Button) findViewById(R.id.btnSetTime);
btnSetTime.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
showDialog(TIME_DIALOG_ID);
}
});
}
private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
timeText.setText(hourOfDay+":"+minute);
};
};
protected Dialog onCreateDialog(int id){
switch(id){
case TIME_DIALOG_ID:
return new TimePickerDialog(this, mTimeSetListener, 0, 0, true);
}
return null;
}
何か助けはありますか?