헤더 항목에 setText를 가져 오는 데 문제가 있습니다. 오류없이 작동합니다. 나는 전화를 시도했다헤더 텍스트 뷰에서 텍스트를 설정할 수 없습니다
내 runnable에서 내 filldata()와 my create에서. 해당 코드의 두 번째 줄이 있으면 충돌합니다. 그렇지 않다면 실행되지만 필요한 결과를 얻지 못할 것입니다. 내가 뭔가를 놓치고있는 것처럼 느껴진다. 그러나 그것이 다른 모든 것을 위해 할 때 헤더가 왜 작동하지 않는지 이해하지 못한다.
public class output extends ListActivity {
private PopupWindow pw;
private dbadapter mydbhelper;
private int getCount = inputpage.editCount;
private Map<Integer, String> values = inputpage.inputValues;
private Cursor st;
@Override
public void onCreate(Bundle savedInstantState){
super.onCreate(savedInstantState);
setContentView(R.layout.outview);
mydbhelper = new dbadapter(this);
mydbhelper.open();
fillData();
}
//Lots of long if statements to insure all text changed has the new color, for statement only colors last item in loop
private final Runnable mTask = new Runnable(){
public void run(){
TextView head = (TextView) findViewById(R.id.storyTitle);
head.setText(st.getString(st.getColumnIndex("titledesc")));
if (getCount == 1){
TextView textView = (TextView)findViewById(R.id.outputText);
String story = textView.getText().toString();
CharSequence modifitedText = Replacer.replace(story,
"0", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(0) +"</font>"));
textView.setText(modifitedText);
}
if (getCount == 2){
TextView textView = (TextView)findViewById(R.id.outputText);
String story = textView.getText().toString();
CharSequence modifitedText = Replacer.replace(story,
"0", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(0) +"</font>"));
CharSequence modifitedText1 = Replacer.replace(modifitedText,
"1", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(1) +"</font>"));
textView.setText(modifitedText1);
}
if (getCount == 3){
TextView textView = (TextView)findViewById(R.id.outputText);
String story = textView.getText().toString();
CharSequence modifitedText = Replacer.replace(story,
"0", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(0) +"</font>"));
CharSequence modifitedText1 = Replacer.replace(modifitedText,
"1", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(1) +"</font>"));
CharSequence modifitedText2 = Replacer.replace(modifitedText1,
"2", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(2) +"</font>"));
textView.setText(modifitedText2);
}
if (getCount == 4){
TextView textView = (TextView)findViewById(R.id.outputText);
String story = textView.getText().toString();
CharSequence modifitedText = Replacer.replace(story,
"0", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(0) +"</font>"));
CharSequence modifitedText1 = Replacer.replace(modifitedText,
"1", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(1) +"</font>"));
CharSequence modifitedText2 = Replacer.replace(modifitedText1,
"2", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(2) +"</font>"));
CharSequence modifitedText3 = Replacer.replace(modifitedText2,
"3", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(3) +"</font>"));
textView.setText(modifitedText3);
}
if (getCount == 5){
TextView textView = (TextView)findViewById(R.id.outputText);
String story = textView.getText().toString();
CharSequence modifitedText = Replacer.replace(story,
"0", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(0) +"</font>"));
CharSequence modifitedText1 = Replacer.replace(modifitedText,
"1", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(1) +"</font>"));
CharSequence modifitedText2 = Replacer.replace(modifitedText1,
"2", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(2) +"</font>"));
CharSequence modifitedText3 = Replacer.replace(modifitedText2,
"3", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(3) +"</font>"));
CharSequence modifitedText4 = Replacer.replace(modifitedText3,
"4", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(4) +"</font>"));
textView.setText(modifitedText4);
}
if (getCount == 6){
TextView textView = (TextView)findViewById(R.id.outputText);
String story = textView.getText().toString();
CharSequence modifitedText = Replacer.replace(story,
"0", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(0) +"</font>"));
CharSequence modifitedText1 = Replacer.replace(modifitedText,
"1", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(1) +"</font>"));
CharSequence modifitedText2 = Replacer.replace(modifitedText1,
"2", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(2) +"</font>"));
CharSequence modifitedText3 = Replacer.replace(modifitedText2,
"3", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(3) +"</font>"));
CharSequence modifitedText4 = Replacer.replace(modifitedText3,
"4", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(4) +"</font>"));
CharSequence modifitedText5 = Replacer.replace(modifitedText4,
"5", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(5) +"</font>"));
textView.setText(modifitedText5);
}
if (getCount == 7){
TextView textView = (TextView)findViewById(R.id.outputText);
String story = textView.getText().toString();
CharSequence modifitedText = Replacer.replace(story,
"0", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(0) +"</font>"));
CharSequence modifitedText1 = Replacer.replace(modifitedText,
"1", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(1) +"</font>"));
CharSequence modifitedText2 = Replacer.replace(modifitedText1,
"2", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(2) +"</font>"));
CharSequence modifitedText3 = Replacer.replace(modifitedText2,
"3", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(3) +"</font>"));
CharSequence modifitedText4 = Replacer.replace(modifitedText3,
"4", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(4) +"</font>"));
CharSequence modifitedText5 = Replacer.replace(modifitedText4,
"5", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(5) +"</font>"));
CharSequence modifitedText6 = Replacer.replace(modifitedText5,
"6", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(6) +"</font>"));
textView.setText(modifitedText6);
}
if (getCount == 8){
TextView textView = (TextView)findViewById(R.id.outputText);
String story = textView.getText().toString();
CharSequence modifitedText = Replacer.replace(story,
"0", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(0) +"</font>"));
CharSequence modifitedText1 = Replacer.replace(modifitedText,
"1", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(1) +"</font>"));
CharSequence modifitedText2 = Replacer.replace(modifitedText1,
"2", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(2) +"</font>"));
CharSequence modifitedText3 = Replacer.replace(modifitedText2,
"3", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(3) +"</font>"));
CharSequence modifitedText4 = Replacer.replace(modifitedText3,
"4", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(4) +"</font>"));
CharSequence modifitedText5 = Replacer.replace(modifitedText4,
"5", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(5) +"</font>"));
CharSequence modifitedText6 = Replacer.replace(modifitedText5,
"6", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(6) +"</font>"));
CharSequence modifitedText7 = Replacer.replace(modifitedText6,
"7", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(7) +"</font>"));
textView.setText(modifitedText7);
}
if (getCount == 9){
TextView textView = (TextView)findViewById(R.id.outputText);
String story = textView.getText().toString();
CharSequence modifitedText = Replacer.replace(story,
"0", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(0) +"</font>"));
CharSequence modifitedText1 = Replacer.replace(modifitedText,
"1", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(1) +"</font>"));
CharSequence modifitedText2 = Replacer.replace(modifitedText1,
"2", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(2) +"</font>"));
CharSequence modifitedText3 = Replacer.replace(modifitedText2,
"3", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(3) +"</font>"));
CharSequence modifitedText4 = Replacer.replace(modifitedText3,
"4", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(4) +"</font>"));
CharSequence modifitedText5 = Replacer.replace(modifitedText4,
"5", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(5) +"</font>"));
CharSequence modifitedText6 = Replacer.replace(modifitedText5,
"6", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(6) +"</font>"));
CharSequence modifitedText7 = Replacer.replace(modifitedText6,
"7", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(7) +"</font>"));
CharSequence modifitedText8 = Replacer.replace(modifitedText7,
"8", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(8) +"</font>"));
textView.setText(modifitedText8);
}
if (getCount == 10){
TextView textView = (TextView)findViewById(R.id.outputText);
String story = textView.getText().toString();
CharSequence modifitedText = Replacer.replace(story,
"0", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(0) +"</font>"));
CharSequence modifitedText1 = Replacer.replace(modifitedText,
"1", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(1) +"</font>"));
CharSequence modifitedText2 = Replacer.replace(modifitedText1,
"2", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(2) +"</font>"));
CharSequence modifitedText3 = Replacer.replace(modifitedText2,
"3", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(3) +"</font>"));
CharSequence modifitedText4 = Replacer.replace(modifitedText3,
"4", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(4) +"</font>"));
CharSequence modifitedText5 = Replacer.replace(modifitedText4,
"5", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(5) +"</font>"));
CharSequence modifitedText6 = Replacer.replace(modifitedText5,
"6", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(6) +"</font>"));
CharSequence modifitedText7 = Replacer.replace(modifitedText6,
"7", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(7) +"</font>"));
CharSequence modifitedText8 = Replacer.replace(modifitedText7,
"8", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(8) +"</font>"));
CharSequence modifitedText9 = Replacer.replace(modifitedText8,
"9", Html.fromHtml("<font color=\"#FFA500\">"+ values.get(9) +"</font>"));
textView.setText(modifitedText9);
}
};};
private final Handler mHandler = new Handler();
//fill listview with data if statement to get quickstart button to work
private void fillData() {
if(main.quickStart == "Cate"){
Cursor st = mydbhelper.getStory();
startManagingCursor(st);
String[] from = new String[] {dbadapter.KEY_TITLESTORY};
int[] to = new int[] {R.id.outputText};
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this, R.layout.out_row, st, from, to);
ListView list = getListView();
View footer = getLayoutInflater().inflate(R.layout.outputbutton, list, false);
View header = getLayoutInflater().inflate(R.layout.outheader, list, false);
list.addHeaderView(header);
list.addFooterView(footer);
setListAdapter(adapter);}
if(main.quickStart == "Quick"){
Cursor st = mydbhelper.getQuickStory();
startManagingCursor(st);
String[] from = new String[] {dbadapter.KEY_TITLESTORY};
int[] to = new int[] {R.id.outputText};
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this, R.layout.out_row, st, from, to);
ListView list = getListView();
View footer = getLayoutInflater().inflate(R.layout.outputbutton, list, false);
View header = getLayoutInflater().inflate(R.layout.outheader, list, false);
list.addHeaderView(header);
list.addFooterView(footer);
setListAdapter(adapter);}
}
public void onClickMenu(View footer){
final MediaPlayer editClickSound = MediaPlayer.create(this, R.raw.button50);
editClickSound.start();
Intent intent = new Intent(this, main.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
@Override
protected void onResume() {
mydbhelper.open();
mHandler.postDelayed(mTask, 10);
super.onResume();
}
@Override
protected void onPause() {
mydbhelper.close();
super.onPause();
}
//Menu Items
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.layout.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.help:
showHelp();
return true;
}
return false;
}
private void showHelp() {
LayoutInflater inflater = (LayoutInflater)
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
pw = new PopupWindow(
inflater.inflate(R.layout.help, null, false),
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,
true);
pw.showAtLocation(this.findViewById(R.id.outputText), Gravity.CENTER, 0, 0);
}
public void onClickHelp(View helper){pw.dismiss();
}
}
로그인 고양이
02-28 01:20:09.750: D/dalvikvm(224): GC freed 519 objects/47136 bytes in 104ms
02-28 01:20:10.360: W/MediaPlayer(224): info/warning (1, 44)
02-28 01:20:10.440: V/DB Exists(224): db exists
02-28 01:20:10.730: I/MediaPlayer(224): Info (1,44)
02-28 01:20:13.260: W/MediaPlayer(224): info/warning (1, 44)
02-28 01:20:13.330: I/MediaPlayer(224): Info (1,44)
02-28 01:20:14.600: W/KeyCharacterMap(224): No keyboard for id 0
02-28 01:20:14.610: W/KeyCharacterMap(224): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
02-28 01:20:18.851: W/MediaPlayer(224): info/warning (1, 44)
02-28 01:20:18.910: I/MediaPlayer(224): Info (1,44)
02-28 01:20:19.220: D/AndroidRuntime(224): Shutting down VM
02-28 01:20:19.220: W/dalvikvm(224): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
02-28 01:20:19.220: E/AndroidRuntime(224): Uncaught handler: thread main exiting due to uncaught exception
02-28 01:20:19.240: E/AndroidRuntime(224): java.lang.NullPointerException
02-28 01:20:19.240: E/AndroidRuntime(224): at wanted.pro.madlibs.output$1.run(output.java:45)
02-28 01:20:19.240: E/AndroidRuntime(224): at android.os.Handler.handleCallback(Handler.java:587)
02-28 01:20:19.240: E/AndroidRuntime(224): at android.os.Handler.dispatchMessage(Handler.java:92)
02-28 01:20:19.240: E/AndroidRuntime(224): at android.os.Looper.loop(Looper.java:123)
02-28 01:20:19.240: E/AndroidRuntime(224): at android.app.ActivityThread.main(ActivityThread.java:4363)
02-28 01:20:19.240: E/AndroidRuntime(224): at java.lang.reflect.Method.invokeNative(Native Method)
02-28 01:20:19.240: E/AndroidRuntime(224): at java.lang.reflect.Method.invoke(Method.java:521)
02-28 01:20:19.240: E/AndroidRuntime(224): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-28 01:20:19.240: E/AndroidRuntime(224): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-28 01:20:19.240: E/AndroidRuntime(224): at dalvik.system.NativeStart.main(Native Method)
02-28 01:20:19.260: I/dalvikvm(224): threadid=7: reacting to signal 3
02-28 01:20:19.300: I/dalvikvm(224): Wrote stack trace to '/data/anr/traces.txt'
02-28 01:20:21.020: I/Process(224): Sending signal. PID: 224 SIG: 9
02-28 01:20:21.980: D/AndroidRuntime(242): Shutting down VM
02-28 01:20:21.980: W/dalvikvm(242): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
02-28 01:20:21.980: E/AndroidRuntime(242): Uncaught handler: thread main exiting due to uncaught exception
02-28 01:20:22.000: E/AndroidRuntime(242): java.lang.RuntimeException: Unable to start activity ComponentInfo{wanted.pro.madlibs/wanted.pro.madlibs.inputpage}: java.lang.NullPointerException
02-28 01:20:22.000: E/AndroidRuntime(242): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
02-28 01:20:22.000: E/AndroidRuntime(242): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
02-28 01:20:22.000: E/AndroidRuntime(242): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
02-28 01:20:22.000: E/AndroidRuntime(242): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
02-28 01:20:22.000: E/AndroidRuntime(242): at android.os.Handler.dispatchMessage(Handler.java:99)
02-28 01:20:22.000: E/AndroidRuntime(242): at android.os.Looper.loop(Looper.java:123)
02-28 01:20:22.000: E/AndroidRuntime(242): at android.app.ActivityThread.main(ActivityThread.java:4363)
02-28 01:20:22.000: E/AndroidRuntime(242): at java.lang.reflect.Method.invokeNative(Native Method)
02-28 01:20:22.000: E/AndroidRuntime(242): at java.lang.reflect.Method.invoke(Method.java:521)
02-28 01:20:22.000: E/AndroidRuntime(242): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-28 01:20:22.000: E/AndroidRuntime(242): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-28 01:20:22.000: E/AndroidRuntime(242): at dalvik.system.NativeStart.main(Native Method)
02-28 01:20:22.000: E/AndroidRuntime(242): Caused by: java.lang.NullPointerException
02-28 01:20:22.000: E/AndroidRuntime(242): at wanted.pro.madlibs.inputpage.onCreate(inputpage.java:51)
02-28 01:20:22.000: E/AndroidRuntime(242): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-28 01:20:22.000: E/AndroidRuntime(242): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
02-28 01:20:22.000: E/AndroidRuntime(242): ... 11 more
02-28 01:20:22.020: I/dalvikvm(242): threadid=7: reacting to signal 3
02-28 01:20:22.070: I/dalvikvm(242): Wrote stack trace to '/data/anr/traces.txt'
02-28 01:20:24.530: D/dalvikvm(250): GC freed 563 objects/48816 bytes in 78ms
02-28 01:20:24.842: W/MediaPlayer(250): info/warning (1, 44)
02-28 01:20:24.940: V/DB Exists(250): db exists
02-28 01:20:25.022: I/MediaPlayer(250): Info (1,44)
음 많은 시행 착오 후에 나는 그것이 작동시킬 수 있었다.
public class output extends ListActivity {
private PopupWindow pw;
private dbadapter mydbhelper;
private int getCount = inputpage.editCount;
private Map<Integer, String> values = inputpage.inputValues;
public Cursor st;
@Override
public void onCreate(Bundle savedInstantState){
super.onCreate(savedInstantState);
setContentView(R.layout.outview);
mydbhelper = new dbadapter(this);
mydbhelper.open();
fillData();
TextView head = (TextView) findViewById(R.id.storyTitle);
st.moveToFirst();
head.setText(st.getString(st.getColumnIndex(dbadapter.KEY_TITLEDESC)));
}
키가 변경되었다고 생각하고 올바른 위치/순서로 호출한다고 생각하십시오. 타이 모든 도움.
if(main.quickStart.equals("Cate"))
및
if(main.quickStart.equals("Quick"))
로그 고양이 – Nitin
atextview.setText (somestring)가 정확한지 확인하십시오. 그건 잘 작동하고, 우리가 그것에 대해 당신에게 말할 수있는 것은 아무것도 없습니다. 예기치 않은 동작이나 오류가있는 경우 해당 문제에 대해 이야기 해보십시오. –
inputpage.java에서 NullPointerException이 발생했습니다. u가 도움을 줄 수 있도록 해당 파일 코드를 제공하십시오. –