android - No compilation Error but aplication is terminating at runtime -


i have problem.

when emulate print_row(int character, int weight, string code) starting , see this: "aplication has stopped unexpectedly".

i don't understand why! there no mistakes @ compilation.

look @ comments in code below...

public class mainactivity extends activity {  private static final string tag = "myactivity";  protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      btncoder = (button) findviewbyid(r.id.btncoder);     btndecoder = (button) findviewbyid(r.id.btndecoder);     incomestr = (edittext) findviewbyid(r.id.incomestr);     tvresult = (textview) findviewbyid(r.id.tvresult);  .... }  public void print_row(int character, int weight, string code) {   log.d(tag,(char)character +"  "+ weight +"  "+ code);   // it's work! table  = (tablelayout) findviewbyid(r.id.table);       //on row terminate...      textview lecter = new textview(getapplicationcontext());     lecter.setgravity(gravity.center_horizontal);     lecter.settextcolor(0xff000000);     lecter.settext("222");      textview l_count = new textview(getapplicationcontext());     l_count.setgravity(gravity.center_horizontal);     l_count.settextcolor(0xff000000);     l_count.settext("222");      textview l_code = new textview(getapplicationcontext());     l_code.setgravity(gravity.center_horizontal);     l_code.settextcolor(0xff000000);     l_code.settext("222");      tablerow row = new tablerow(getapplicationcontext());     row.addview(lecter);     row.addview(l_count);      row.addview(l_code);       table.addview(row);  } 

}

it 1 activity application, it's have 1 layout. if make on create() - right

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      table  = (tablelayout) findviewbyid(r.id.table);      textview lecter = new textview(getapplicationcontext());     lecter.setgravity(gravity.center_horizontal);     lecter.settextcolor(0xff000000);     lecter.settext("222");      textview l_count = new textview(getapplicationcontext());     l_count.setgravity(gravity.center_horizontal);     l_count.settextcolor(0xff000000);     l_count.settext("222");      textview l_code = new textview(getapplicationcontext());     l_code.setgravity(gravity.center_horizontal);     l_code.settextcolor(0xff000000);     l_code.settext("222");      tablerow row = new tablerow(getapplicationcontext());     row.addview(lecter);     row.addview(l_count);      row.addview(l_code);       table.addview(row);  } 

and class function caused...

public class tree { listview lvdata;     public tree() {}    public tree(int character, int weight, boolean leaf) {      this.leaf = leaf;      this.character = character;      this.weight = weight;    }  @targetapi(build.version_codes.honeycomb) @suppresslint("newapi") public void traverse(string code, huffman h) throws ioexception {     if (leaf) {          mainactivity m = new mainactivity();          m.print_row((char)character, weight, code);       }        if ( child0 != null) child0.traverse(code + "0", h);       if ( child1 != null) child1.traverse(code + "1", h);    } } 

and pieces of layout...

<tablelayout android:layout_width="fill_parent"                  android:layout_height="wrap_content"                  android:stretchcolumns="*"                  android:id="@+id/table">         <tablerow android:id="@+id/header"                   android:padding="5dp"                   android:background="#ccc">             <textview android:text="char"                       android:layout_gravity="center"                     />             <textview android:text="count"                       android:layout_gravity="center"                     />             <textview android:text="bit - kod"                       android:layout_gravity="center"                     />         </tablerow>     </tablelayout> 

logcat content:

    07-01 11:26:12.822: d/myactivity(466): b  2  000 07-01 11:26:12.822: d/myactivity(466): b  2  000 07-01 11:26:12.822: d/androidruntime(466): shutting down vm 07-01 11:26:12.822: w/dalvikvm(466): threadid=1: thread exiting uncaught exception (group=0x40015560) 07-01 11:26:12.841: e/androidruntime(466): fatal exception: main 07-01 11:26:12.841: e/androidruntime(466): java.lang.nullpointerexception 07-01 11:26:12.841: e/androidruntime(466):  @ android.app.activity.findviewbyid(activity.java:1647) 07-01 11:26:12.841: e/androidruntime(466):  @ com.example.m_huffman.mainactivity.print_row(mainactivity.java:77) 07-01 11:26:12.841: e/androidruntime(466):  @ com.example.m_huffman.tree.traverse(tree.java:36) 07-01 11:26:12.841: e/androidruntime(466):  @ com.example.m_huffman.tree.traverse(tree.java:39) 07-01 11:26:12.841: e/androidruntime(466):  @ com.example.m_huffman.tree.traverse(tree.java:39) 07-01 11:26:12.841: e/androidruntime(466):  @ com.example.m_huffman.tree.traverse(tree.java:39) 07-01 11:26:12.841: e/androidruntime(466):  @ com.example.m_huffman.huffman.makecode(huffman.java:41) 07-01 11:26:12.841: e/androidruntime(466):  @ com.example.m_huffman.mainactivity$1.onclick(mainactivity.java:45) 07-01 11:26:12.841: e/androidruntime(466):  @ android.view.view.performclick(view.java:2485) 07-01 11:26:12.841: e/androidruntime(466):  @ android.view.view$performclick.run(view.java:9080) 07-01 11:26:12.841: e/androidruntime(466):  @ android.os.handler.handlecallback(handler.java:587) 07-01 11:26:12.841: e/androidruntime(466):  @ android.os.handler.dispatchmessage(handler.java:92) 07-01 11:26:12.841: e/androidruntime(466):  @ android.os.looper.loop(looper.java:123) 07-01 11:26:12.841: e/androidruntime(466):  @ android.app.activitythread.main(activitythread.java:3683) 07-01 11:26:12.841: e/androidruntime(466):  @ java.lang.reflect.method.invokenative(native method) 07-01 11:26:12.841: e/androidruntime(466):  @ java.lang.reflect.method.invoke(method.java:507) 07-01 11:26:12.841: e/androidruntime(466):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 07-01 11:26:12.841: e/androidruntime(466):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 07-01 11:26:12.841: e/androidruntime(466):  @ dalvik.system.nativestart.main(native method) 07-01 11:26:12.852: w/activitymanager(70):   force finishing activity com.example.m_huffman/.mainactivity 07-01 11:26:13.412: w/activitymanager(70): activity pause timeout historyrecord{406139d0 com.example.m_huffman/.mainactivity} 07-01 11:26:14.541: i/process(466): sending signal. pid: 466 sig: 9 07-01 11:26:14.551: i/windowmanager(70): win death: window{406bd110 com.example.m_huffman/com.example.m_huffman.mainactivity paused=false} 07-01 11:26:14.561: i/activitymanager(70): process com.example.m_huffman (pid 466) has died. 07-01 11:26:14.691: w/inputmanagerservice(70): got remoteexception sending setactive(false) notification pid 466 uid 10054 

thanks.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -