Posts

java - "Null object" error when setting a adapter -

this question has answer here: what nullpointerexception, , how fix it? 12 answers i'm getting error when set adapter. have listview id lv_cine in view. edit 1: added wrong codes same this. edit 2: ok managed past first error, i'm getting similar one: 12-01 20:43:44.445 7617-7617/com.example.maria.maria e/androidruntime﹕ fatal exception: main process: com.example.maria.maria, pid: 7617 java.lang.nullpointerexception: attempt invoke interface method 'int java.util.list.size()' on null object reference @ android.widget.simpleadapter.getcount(simpleadapter.java:93) @ android.widget.listview.setadapter(listview.java:487) @ com.example.maria.maria.cinema$getcontacts.onpostexecute(cinema.java:146) @ com.example.maria.maria.cinema$getcontacts.onpostexecute(cinema.java:67) @ android...

string - MATLAB: populate cell array and format number -

what's efficient way populate cell array values vector (each formatted differently). for example: v = [12.3 .004 3 4.222]; desired cell array: array = {'a = 12.30' 'b = 0.004' 'c = 3' 'd = 4'}; is there easier way calling sprintf each , every cell? array = {sprintf('a = %.2f',v(1)) sprintf('b = %.3f',v(2)) ... } there's no vectorized form of sprintf supports different formats, you're stuck sprintf call per cell. arrange code easier deal in loop. v = [12.3 .004 3 4.222]; names = num2cell('a':'z'); formats = { '%.2f' '%.3f' '%d' '%.0f' }; c = cell(size(v)); = numel(v) c{i} = sprintf(['%s = ' formats{i}], names{i}, v(i)); end it tricky faster naive way without dropping down java or c, because it's still going take sprintf() call each cell, , that's going dominate execution time. if have large number of elements , relatively sma...

C: write (and then read) a string to file using a hash function to locate the byte's position -

i want write 1kb file, , want use hash function calculate position of byte i'm going write. want able later retrieve data in correct order. to locate position of byte read/write use hash function f = (index*prime) mod 1024 where index index in string, , prime prime number need avoid collisions, i.e. not rewriting 2 times in same position. f, strlen (b first create file dd bs=1024 count=1 if=/dev/zero of=test.fs and after compile , run program passing "w" parameter $ ./a.out w now, seems me write() function job correctly, because if do... $ cat test.fs or $ hexdump test.fs ... can see content of file consistent string inserted! however, if run read-mode passing "r" parameter, curious random output, seems me if i'm reading thrash memory. cannot understand read() function fails, thank in advance. the c code follows: #include <stdio.h> #include <string.h> #define prime 7919 int main(int argc, char *argv[]) { int ...

git - How Do Unmerged Paths in Index Occur -

in "git status" man page, there table describes meaning of xy status code when short-format or porcelain format used. specifically, table is: x y meaning ------------------------------------------------- [md] not updated m [ md] updated in index [ md] added index d [ m] deleted index r [ md] renamed in index c [ md] copied in index [marc] index , work tree matches [ marc] m work tree changed since index [ marc] d deleted in work tree ------------------------------------------------- d d unmerged, both deleted u unmerged, added u d unmerged, deleted them u unmerged, added them d u unmerged, deleted unmerged, both added u u unmerged, both modified ------------------------------------------------- ? ? untracked ! ! ignored ------------------------------------------...

r - Require lib.loc and Required base packages -

say have set of external packages in folder x . , want load 1 of these packages, example through require(my.package, lib.loc='x') any requirement (dependency) of my.package external, looked in same folder x . base packages? need copy base packages folder x or r fallback default folder despite different lib.loc specified? so tried right new set , observed @ least on mac os x, base packages still included default lib path.

scala - Access data files in production play server -

i have play in scala application directory structure looks this: app conf data <- added manutally logs project public target test the data directory have manually added, contains number of json files application depends on. getting hold of them in code seems easy enough, , works when run "play run". code use reference them: val projectroot = play.application.path.getabsolutepath val statfiles = new file(projectroot + "/data/"+tier+"/usage").listfiles however, when run "play start" nullpointerexceptions, stack trace looks this: caused by: java.lang.nullpointerexception: null @ scala.collection.mutable.arrayops$ofref$.length$extension(arrayops.scala:192) ~[org.scala-lang.scala-library-2.11.1.jar:na] @ scala.collection.mutable.arrayops$ofref.length(arrayops.scala:192) ~[org.scala-lang.scala-library-2.11.1.jar:na] @ scala.collection.seqlike$class.size(seqlike.scala:106) ~[org.scala-lang.scala-library-2.11.1.jar:na] @ sc...

How to accept two connections using sockets in Python -

i working on chat program. right can except 1 client. how make can accept 2 clients? still bit of noob when comes sockets can explain thoroughly? server code: import socket def mainfunc(): host = "" port = 50000 iplist = [] nicknamelist = [] num = true s = socket.socket() s.bind((host, port)) s.listen(1) c, addr = s.accept() print("connection from: " + str(addr) + "\n") iplist.insert(0, str(addr)) while true: data = c.recv(1024) if not data: break if num == true: nicknamelist.insert(0, str(data)) num = false else: print("from " + nicknamelist[0] + ": " + str(data) + "\n") message = raw_input("message want send: ") print("\n") c.send(message) c.close() i have tried changing s.listen(1) s.listen(2). did not seem allow second...