Hoi,
Ik ben dus bezig met een nieuwe activty voor de instellingen, alleen nu crasht de app en ik weet niet wat ik er mee moet doen, in Eclpise zijn geen errors.
AndroidManifest.xml:
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package="nl.dylaan.deroosterapp"
android:versionCode="1"
android:versionName="1.0" >
android:minSdkVersion="14"
android:targetSdkVersion="17" />
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.NoTitle" >
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="@string/app_name" >
prefs.xml (gewoon van de android site afgehaald)
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
xmlns:android="http://schemas.android.com/apk/res/android">
android:title="test">
android:key="checkbox_preference"
android:title="test"
android:summary="test" />
android:title="test">
android:key="edittext_preference"
android:title="test"
android:summary="test"
android:dialogTitle="test" />
android:key="list_preference"
android:title="test"
android:summary="test"
android:entries="@array/Scholen"
android:entryValues="@array/Scholen"
android:dialogTitle="test" />
android:title="test">
android:key="screen_preference"
android:title="test"
android:summary="test">
android:key="next_screen_checkbox_preference"
android:title="test"
android:summary="test" />
android:title="test"
android:summary="test">
android:data="http://www.android.com" />
android:title="test">
android:key="parent_checkbox_preference"
android:title="test"
android:summary="test" />
android:key="child_checkbox_preference"
android:dependency="parent_checkbox_preference"
android:layout="?android:attr/preferenceLayoutChild"
android:title="test"
android:summary="test" />
Mainactivity.java:
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package nl.dylaan.deroosterapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
private boolean isChecked = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Messages.say(this, "Bezig met het controleren van een internet verbinding!");
if(Check.isInternetAvailable()) {
Messages.say(this, "Je hebt een internet verbinding. Bezig met updaten van de lokale database.");
isChecked = true;
} else {
Messages.say(this, "Je hebt geen internet verbinding of de website is onbereikbaar. Bezig met ophalen van de lokale database.");
isChecked = false;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.clear();
if(isChecked == true) {
getMenuInflater().inflate(R.menu.main, menu);
} else {
getMenuInflater().inflate(R.menu.none, menu);
}
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
Intent intent = new Intent(this, Preferences.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
Preferences.java:
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package nl.dylaan.deroosterapp;
import android.os.Bundle;
import android.preference.PreferenceFragment;
public class Preferences extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.prefs);
}
}
Wanneer ik de instellingen open krijg ik een melding De Rooster App is gestopt, in ecplise krijg ik helaas geen errors. Weet iemand waaraan het ligt?
toevoeging op 12 oktober 2014, 17
02:
Toch wel:
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
10-12 17:09:16.995: E/AndroidRuntime(12399): FATAL EXCEPTION: main
10-12 17:09:16.995: E/AndroidRuntime(12399): Process: nl.dylaan.deroosterapp, PID: 12399
10-12 17:09:16.995: E/AndroidRuntime(12399): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{nl.dylaan.deroosterapp/nl.dylaan.deroosterapp.Preferences}: java.lang.ClassCastException: nl.dylaan.deroosterapp.Preferences cannot be cast to android.app.Activity
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.app.ActivityThread.access$900(ActivityThread.java:161)
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.os.Handler.dispatchMessage(Handler.java:102)
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.os.Looper.loop(Looper.java:157)
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.app.ActivityThread.main(ActivityThread.java:5356)
10-12 17:09:16.995: E/AndroidRuntime(12399): at java.lang.reflect.Method.invokeNative(Native Method)
10-12 17:09:16.995: E/AndroidRuntime(12399): at java.lang.reflect.Method.invoke(Method.java:515)
10-12 17:09:16.995: E/AndroidRuntime(12399): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
10-12 17:09:16.995: E/AndroidRuntime(12399): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
10-12 17:09:16.995: E/AndroidRuntime(12399): at dalvik.system.NativeStart.main(Native Method)
10-12 17:09:16.995: E/AndroidRuntime(12399): Caused by: java.lang.ClassCastException: nl.dylaan.deroosterapp.Preferences cannot be cast to android.app.Activity
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2222)
10-12 17:09:16.995: E/AndroidRuntime(12399): ... 11 more
Ik ben dus bezig met een nieuwe activty voor de instellingen, alleen nu crasht de app en ik weet niet wat ik er mee moet doen, in Eclpise zijn geen errors.
AndroidManifest.xml:
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package="nl.dylaan.deroosterapp"
android:versionCode="1"
android:versionName="1.0" >
android:minSdkVersion="14"
android:targetSdkVersion="17" />
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.NoTitle" >
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="@string/app_name" >
prefs.xml (gewoon van de android site afgehaald)
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
xmlns:android="http://schemas.android.com/apk/res/android">
android:title="test">
android:key="checkbox_preference"
android:title="test"
android:summary="test" />
android:title="test">
android:key="edittext_preference"
android:title="test"
android:summary="test"
android:dialogTitle="test" />
android:key="list_preference"
android:title="test"
android:summary="test"
android:entries="@array/Scholen"
android:entryValues="@array/Scholen"
android:dialogTitle="test" />
android:title="test">
android:key="screen_preference"
android:title="test"
android:summary="test">
android:key="next_screen_checkbox_preference"
android:title="test"
android:summary="test" />
android:title="test"
android:summary="test">
android:data="http://www.android.com" />
android:title="test">
android:key="parent_checkbox_preference"
android:title="test"
android:summary="test" />
android:key="child_checkbox_preference"
android:dependency="parent_checkbox_preference"
android:layout="?android:attr/preferenceLayoutChild"
android:title="test"
android:summary="test" />
Mainactivity.java:
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package nl.dylaan.deroosterapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
private boolean isChecked = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Messages.say(this, "Bezig met het controleren van een internet verbinding!");
if(Check.isInternetAvailable()) {
Messages.say(this, "Je hebt een internet verbinding. Bezig met updaten van de lokale database.");
isChecked = true;
} else {
Messages.say(this, "Je hebt geen internet verbinding of de website is onbereikbaar. Bezig met ophalen van de lokale database.");
isChecked = false;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.clear();
if(isChecked == true) {
getMenuInflater().inflate(R.menu.main, menu);
} else {
getMenuInflater().inflate(R.menu.none, menu);
}
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
Intent intent = new Intent(this, Preferences.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
Preferences.java:
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package nl.dylaan.deroosterapp;
import android.os.Bundle;
import android.preference.PreferenceFragment;
public class Preferences extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.prefs);
}
}
Wanneer ik de instellingen open krijg ik een melding De Rooster App is gestopt, in ecplise krijg ik helaas geen errors. Weet iemand waaraan het ligt?
toevoeging op 12 oktober 2014, 17
02:Toch wel:
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
10-12 17:09:16.995: E/AndroidRuntime(12399): FATAL EXCEPTION: main
10-12 17:09:16.995: E/AndroidRuntime(12399): Process: nl.dylaan.deroosterapp, PID: 12399
10-12 17:09:16.995: E/AndroidRuntime(12399): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{nl.dylaan.deroosterapp/nl.dylaan.deroosterapp.Preferences}: java.lang.ClassCastException: nl.dylaan.deroosterapp.Preferences cannot be cast to android.app.Activity
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.app.ActivityThread.access$900(ActivityThread.java:161)
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.os.Handler.dispatchMessage(Handler.java:102)
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.os.Looper.loop(Looper.java:157)
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.app.ActivityThread.main(ActivityThread.java:5356)
10-12 17:09:16.995: E/AndroidRuntime(12399): at java.lang.reflect.Method.invokeNative(Native Method)
10-12 17:09:16.995: E/AndroidRuntime(12399): at java.lang.reflect.Method.invoke(Method.java:515)
10-12 17:09:16.995: E/AndroidRuntime(12399): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
10-12 17:09:16.995: E/AndroidRuntime(12399): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
10-12 17:09:16.995: E/AndroidRuntime(12399): at dalvik.system.NativeStart.main(Native Method)
10-12 17:09:16.995: E/AndroidRuntime(12399): Caused by: java.lang.ClassCastException: nl.dylaan.deroosterapp.Preferences cannot be cast to android.app.Activity
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
10-12 17:09:16.995: E/AndroidRuntime(12399): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2222)
10-12 17:09:16.995: E/AndroidRuntime(12399): ... 11 more

