我有一个问题是我的代码:
package de.retowaelchli.filterit;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.RadioGroup;
import de.retowaelchli.filterit.database.ADFilterDBAdapter;
public class ADFilterConfigActivity extends Activity {
//Variablen deklaration
private ADFilterDBAdapter mDbHelper;
private String name;
private String keyword;
private String cache;
private String save;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.autodelete_config);
radiobuttoncheck();
//Hier wir die Datenbank aufgerufen
mDbHelper = new ADFilterDBAdapter(this);
mDbHelper.open();
//Hier werden die EditTextfelder gesucht
EditText edtTextName=(EditText )findViewById(R.id.ADConfigName);
EditText edtTextKeyword=(EditText )findViewById(R.id.ADConfigKeyword);
//Hier wird der Inhalt der EditText boxen in einen String gespeichert
name = edtTextName.getText().toString();
keyword = edtTextKeyword.getText().toString();
}
private void radiobuttoncheck() {
//Hier wird ausgewertet welcher Button geklickt wurde
RadioGroup rg = (RadioGroup) findViewById(R.id.adcachegroup);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, final int checkedId) {
switch (checkedId) {
case R.id.adcache_true:
save = new StringBuilder(save).append("true").toString();
cache = save.toString();
break;
case R.id.adcache_false:
save = new StringBuilder(save).append("false").toString();
cache = save.toString();
break;
}
}
});
}
}
代码在Eclipse中没有显示一个错误,但如果我尝试在我的手机上测试代码,我会得到一个ForceClose。
我发现如果我不使用radiobuttoncheck它是有效的。但我不知道其中的错误。
提前进行
狩猎
抱歉忘记了logcat-log: 08-31 10:35:22.823: INFO/ActivityManager(1740): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=de.retowaelchli.filterit/.StartseiteActivity } from pid 1867
08-31 10:35:22.843: VERBOSE/HtcAppUsageStats(1740): (launch app, package): (Filter It, de.retowaelchli.filterit)
08-31 10:35:22.863: INFO/ActivityManager(1740): Start proc de.retowaelchli.filterit for activity de.retowaelchli.filterit/.StartseiteActivity: pid=27542 uid=10150 gids={}
08-31 10:35:22.933: DEBUG/dalvikvm(1541): GC_EXPLICIT freed 11K, 51% free 2684K/5379K, external 0K/0K, paused 78ms
08-31 10:35:23.033: INFO/SuperPowerSvc(2428): [SuperPowerSvc] App launched: [de.retowaelchli.filterit]
08-31 10:35:23.063: DEBUG/dalvikvm(1541): GC_EXPLICIT freed <1K, 51% free 2684K/5379K, external 0K/0K, paused 88ms
08-31 10:35:23.143: DEBUG/dalvikvm(1541): GC_EXPLICIT freed <1K, 51% free 2684K/5379K, external 0K/0K, paused 67ms
08-31 10:35:23.223: DEBUG/dalvikvm(1740): GC_EXTERNAL_ALLOC freed 659K, 35% free 9759K/14855K, external 9725K/11773K, paused 151ms
08-31 10:35:23.473: WARN/ResourceType(1740): Skipping entry 0x7f040007 in package table 0 because it is not complex!
08-31 10:35:23.483: WARN/ResourceType(1740): Skipping entry 0x7f040008 in package table 0 because it is not complex!
08-31 10:35:23.603: DEBUG/dalvikvm(27542): GC_EXTERNAL_ALLOC freed 50K, 50% free 2694K/5379K, external 0K/0K, paused 45ms
08-31 10:35:23.733: WARN/InputManagerService(1740): [unbindCurrentClientLocked] Disable input method client.
08-31 10:35:23.733: WARN/InputManagerService(1740): [startInputLocked] Enable input method client.
08-31 10:35:23.803: INFO/ActivityManager(1740): Displayed de.retowaelchli.filterit/.StartseiteActivity: +947ms (total +1m12s949ms)
08-31 10:35:24.963: INFO/ActivityManager(1740): Starting activity: Intent { cmp=de.retowaelchli.filterit/.ADeleteActivity } from pid 27542
08-31 10:35:24.973: INFO/SuperPowerSvc(2428): [SuperPowerSvc] App launched: [de.retowaelchli.filterit]
08-31 10:35:25.113: DEBUG/dalvikvm(27542): GC_EXTERNAL_ALLOC freed 36K, 49% free 2767K/5379K, external 5760K/7192K, paused 21ms
08-31 10:35:25.313: INFO/ActivityManager(1740): Displayed de.retowaelchli.filterit/.ADeleteActivity: +350ms
08-31 10:35:26.743: INFO/ActivityManager(1740): Starting activity: Intent { cmp=de.retowaelchli.filterit/.ADFilterConfigActivity } from pid 27542
08-31 10:35:26.783: INFO/[POST_RESELECT](27542): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$START@401090b8,-1,0,-1,0)
08-31 10:35:26.783: INFO/[POST_RESELECT](27542): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$END@40130050,-1,0,-1,0)
08-31 10:35:26.783: INFO/[POST_RESELECT](27542): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$START@401090b8,-1,0,-1,0)
08-31 10:35:26.783: INFO/[POST_RESELECT](27542): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$END@40130050,-1,0,-1,0)
08-31 10:35:26.803: DEBUG/AndroidRuntime(27542): Shutting down VM
08-31 10:35:26.803: WARN/dalvikvm(27542): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): FATAL EXCEPTION: main
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.retowaelchli.filterit/de.retowaelchli.filterit.ADFilterConfigActivity}: java.lang.NullPointerException
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at android.app.ActivityThread.access$1500(ActivityThread.java:132)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at android.os.Handler.dispatchMessage(Handler.java:99)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at android.os.Looper.loop(Looper.java:143)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at android.app.ActivityThread.main(ActivityThread.java:4196)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at java.lang.reflect.Method.invokeNative(Native Method)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at java.lang.reflect.Method.invoke(Method.java:507)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at dalvik.system.NativeStart.main(Native Method)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): Caused by: java.lang.NullPointerException
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at de.retowaelchli.filterit.ADFilterConfigActivity.radiobuttoncheck(ADFilterConfigActivity.java:46)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at de.retowaelchli.filterit.ADFilterConfigActivity.onCreate(ADFilterConfigActivity.java:26)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
08-31 10:35:26.803: ERROR/AndroidRuntime(27542): ... 11 more
08-31 10:35:26.813: WARN/ActivityManager(1740): Force finishing activity de.retowaelchli.filterit/.ADFilterConfigActivity
08-31 10:35:26.813: WARN/ActivityManager(1740): Force finishing activity de.retowaelchli.filterit/.ADeleteActivity
08-31 10:35:26.873: INFO/SuperPowerSvc(2428): [SuperPowerSvc] App launched: [de.retowaelchli.filterit]
08-31 10:35:27.323: WARN/ActivityManager(1740): Activity pause timeout for HistoryRecord{4094f4d8 de.retowaelchli.filterit/.ADFilterConfigActivity}
最后是布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
style="@style/NormalFont"
android:text="@string/adconfig"
android:layout_weight="0.05"
android:clickable="false"
/>
<TextView
style="@style/SmallFont"
android:text="@string/adname"
android:layout_weight="0.03" />
<EditText
android:layout_width="match_parent"
android:id="@+id/ADConfigName"
android:layout_weight="0.05"
android:layout_height="25dp"
android:layout_marginBottom="20dp">
<requestFocus></requestFocus>
</EditText>
<TextView
style="@style/SmallFont"
android:text="@string/adkeyword"
android:layout_weight="0.03"
/>
<EditText
android:layout_width="match_parent"
android:id="@+id/ADConfigKeyword"
android:layout_weight="0.05"
android:layout_height="25dp"
android:layout_marginBottom="20dp">
<requestFocus></requestFocus>
</EditText>
<TextView
style="@style/SmallFont"
android:text="@string/adcache"
android:layout_weight="0.03"
/>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:checkedButton="@+id/adcachegroup"
android:id="@+id/adcache"
android:gravity="center" >
<RadioButton
android:text="Yes"
android:id="@+id/adcache_true"
android:layout_width="80dip"
android:layout_height="wrap_content"
>
</RadioButton>
<RadioButton
android:text="No"
android:id="@+id/adcache_false"
android:layout_width="80dip"
android:layout_height="wrap_content">
</RadioButton>
</RadioGroup>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/ADConfigMainsite"
android:layout_weight="0.76"
android:gravity="bottom">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ADConfigMainsite"
android:onClick="onClickADConfigSave"
android:layout_weight="0.05"
android:gravity="bottom">
<TextView
android:text="@string/adconfigsave"
style="@style/NormalFont"
android:gravity="bottom"/>
</TableRow>
</TableLayout>
</LinearLayout>
答案 0 :(得分:0)
您无法使用StringBuilder
字符串创建null
:
save = new StringBuilder(save).append("true").toString();
初始化save
字符串:
private String save = "";
编辑:根据无法在布局中找到标识为adcachegroup
的locgat输出窗口小部件。确保您正在设置正确的布局。