私はAndroidプログラミングに不慣れで、日常のタスクを管理するためのアプリを作成しようとしていました。これで、アプリケーションはアクティビティを切り替える必要があります。通常は最初のアクティビティで開始されますが、ボタンをクリックして他のアクティビティに移動すると、アプリがクラッシュします。私は自分の携帯電話(Galaxy s3)に直接デバッグしています。
logcatの出力は、他の質問で大いに役立つことに気付いたので、役立つかもしれないと思いました。
09-24 05:49:14.807: D/dalvikvm(9062): GC_FOR_ALLOC freed 137K, 4% free 12835K/13255K, paused 25ms
09-24 05:49:14.807: I/dalvikvm-heap(9062): Grow heap (frag case) to 13.065MB for 379472-byte allocation
09-24 05:49:14.837: D/dalvikvm(9062): GC_FOR_ALLOC freed <1K, 4% free 13205K/13639K, paused 11ms
09-24 05:49:14.862: D/AbsListView(9062): Get MotionRecognitionManager
09-24 05:49:16.102: D/CLIPBOARD(9062): Hide Clipboard dialog at Starting input: finished by someone else... !
09-24 05:49:22.282: D/AndroidRuntime(9062): Shutting down VM
09-24 05:49:22.282: W/dalvikvm(9062): threadid=1: thread exiting with uncaught exception (group=0x40c661f8)
09-24 05:49:22.297: E/AndroidRuntime(9062): FATAL EXCEPTION: main
09-24 05:49:22.297: E/AndroidRuntime(9062): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dailyplanner/com.example.dailyplanner.new_task}: java.lang.RuntimeException: Binary XML file line #24: You must supply a layout_width attribute.
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.app.ActivityThread.access$600(ActivityThread.java:128)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.os.Handler.dispatchMessage(Handler.java:99)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.os.Looper.loop(Looper.java:137)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.app.ActivityThread.main(ActivityThread.java:4514)
09-24 05:49:22.297: E/AndroidRuntime(9062): at java.lang.reflect.Method.invokeNative(Native Method)
09-24 05:49:22.297: E/AndroidRuntime(9062): at java.lang.reflect.Method.invoke(Method.java:511)
09-24 05:49:22.297: E/AndroidRuntime(9062): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
09-24 05:49:22.297: E/AndroidRuntime(9062): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
09-24 05:49:22.297: E/AndroidRuntime(9062): at dalvik.system.NativeStart.main(Native Method)
09-24 05:49:22.297: E/AndroidRuntime(9062): Caused by: java.lang.RuntimeException: Binary XML file line #24: You must supply a layout_width attribute.
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:491)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:5331)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:5452)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.widget.RelativeLayout$LayoutParams.<init>(RelativeLayout.java:1064)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:933)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:69)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.view.LayoutInflater.rInflate(LayoutInflater.java:741)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
09-24 05:49:22.297: E/AndroidRuntime(9062): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:280)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.app.Activity.setContentView(Activity.java:1892)
09-24 05:49:22.297: E/AndroidRuntime(9062): at com.example.dailyplanner.new_task.onCreate(new_task.java:23)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.app.Activity.performCreate(Activity.java:4562)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
09-24 05:49:22.297: E/AndroidRuntime(9062): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
09-24 05:49:22.297: E/AndroidRuntime(9062): ... 11 more
09-24 05:49:22.317: D/dalvikvm(9062): GC_CONCURRENT freed 164K, 3% free 13459K/13831K, paused 1ms+2ms
09-24 05:49:22.322: E/SQLiteDatabase(9062): close() was never explicitly called on database '/data/data/com.example.dailyplanner/databases/MyDB'
09-24 05:49:22.322: E/SQLiteDatabase(9062): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:2064)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1118)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1075)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1051)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1154)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1147)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:860)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:222)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at com.example.dailyplanner.MainActivity.onCreate(MainActivity.java:24)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.app.Activity.performCreate(Activity.java:4562)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.app.ActivityThread.access$600(ActivityThread.java:128)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.os.Handler.dispatchMessage(Handler.java:99)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.os.Looper.loop(Looper.java:137)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at android.app.ActivityThread.main(ActivityThread.java:4514)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at java.lang.reflect.Method.invokeNative(Native Method)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at java.lang.reflect.Method.invoke(Method.java:511)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
09-24 05:49:22.322: E/SQLiteDatabase(9062): at dalvik.system.NativeStart.main(Native Method)`
これが私のAndroidマニフェストです:
<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>
`
2つのJavaファイルのコードは次のとおりです。
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(MainActivity.this, new_task.class);
startActivity(nTaskScreen);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
2番目のファイル:
import android.R.string;
import android.app.Activity;
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 {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.new_task);
TextView timeTxt = (TextView) findViewById(R.id.timeTxt);
TextView dateTxt = (TextView) findViewById(R.id.dateTxt);
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) {
}
});
}
}
どんな助けもいただければ幸いです:)