Hi,
ich bin gerade echt am verzweifeln anscheinend muss der Fehler offensichtlich sein, aber ich seh gerade den Wald vor lauter Bäumen nicht.
Und zwar wirft LogCat bei startActivity() eine NPE und ich sehs einfach nicht.
Hier ist die Hauptactivity:
Java
package com.dulcetcodes.studienplaner;
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class HomeActivity extends Activity {
SQLiteDatabase myDB = null;
final static String MY_DB_NAME = "studi";
final static String MY_DB_TABLE_SCHEDULE = "schedule";
final static String MY_DB_TABLE_NOTES = "notes";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//onCreateDBAndDBTabled();
setContentView(R.layout.main);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.menuDay:
Intent intent = new Intent(this, DayActivity.class);
startActivity(intent);
break;
case R.id.menuCalendar:
// Open CalendarActivity
break;
}
return super.onOptionsItemSelected(item);
}
}
Alles anzeigen
Hier die zweite Activity:
Java
package com.dulcetcodes.studienplaner;
import java.util.Calendar;
import java.util.GregorianCalendar;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class DayActivity extends Activity {
//SQLiteDatabase myDB = null;
TextView text = (TextView) findViewById(R.id.day);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
* myDB = this.openOrCreateDatabase(HomeActivity.MY_DB_NAME,
* MODE_PRIVATE, null);
*
* Cursor c =
* myDB.rawQuery("SELECT _id, name_con, start, end, type, prof, room FROM "
* + HomeActivity.MY_DB_TABLE_SCHEDULE + "WHERE day;", null);
* startManagingCursor(c);
*/
setContentView(R.layout.day);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
text.setText("" + getDay());
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}
/*@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.menuCalendar:
// Open CalendarActivity
break;
}
return super.onOptionsItemSelected(item);
}*/
public int getDay() {
GregorianCalendar newCal = new GregorianCalendar();
int day = newCal.get(Calendar.DAY_OF_WEEK);
return day;
}
}
Alles anzeigen
Und hier das Manifest:
Java
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dulcetcodes.studienplaner"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".DayActivity"
android:label="@string/app_name"/>
<activity android:name=".HomeActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Alles anzeigen
Und genau hier hakt es:
Java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.menuDay:
Intent intent = new Intent(this, DayActivity.class);
startActivity(intent);
break;
}
return super.onOptionsItemSelected(item);
}
Alles anzeigen
Ruf ich statt DayActivity die HomeActivity auf, funktioniert alles reibungslos. Aber sobald ich ich die andere versuch aufzurufen crashed es mit NPE. LogCat liefert mir leider nicht wirklich was.
Ich hoffe ihr seht den Fehler, ich weiß es nicht worans liegt.