Во-первых, всегда нужно быть внимательнее. Во-вторых, можно было бы и самому разобраться, не так уж всё это и сложно. у тебя там фор был один не совсем правильный | Код | int size = index.size(); int elm = Integer.parseInt((index.elementAt(r.nextInt(size)))+""); long skip=0; for (int i = 0; i < size; i++) { skip+=Long.parseLong(index.elementAt(i)+""); }
|
я поправил на
| Код | int size = index.size(); int elm = Integer.parseInt((index.elementAt(r.nextInt(size)))+""); long skip=0; for (int i = 0; i < elm; i++) { skip+=Long.parseLong(index.elementAt(i)+""); }
|
так оно логичнее. Плюс тут есть ещё над чем поработать и что с оптимизировать. Но в целом, картина уже прояснилась и работает  Но а то что не в понедельник, ну милок звини, у всех работа ещё своя имеется  полностью код смотри НИЖЕ. Думаю проанализировать и понять что у тебя и где было не так ты сможешь, если нет....... тут тогда тебе уже точно никто не поможет.
За сим, разшрешите откланиться.
| Код | /* * FunySms.java * * Created on 19. Mai 2006, 13:24 */
//import com.sun.midp.lcdui.Text; import java.io.*; import java.util.*; import javax.microedition.io.*; import javax.microedition.midlet.*; import javax.microedition.lcdui.*;
/** * * @author Unkis */ public class SMSSeek extends MIDlet implements CommandListener { private String[] mygroup = {"Send via SMS","New SMS","Exit"}; private double time; private Vector index = new Vector(); /** Creates a new instance of FunySms */ public SMSSeek() { initialize(); } private Form hauptForm;//GEN-BEGIN:MVDFields private Command exitCommand1; private Command okCommand1; private Command nextTextCommand; private Display disp; private TextField smsField;//GEN-END:MVDFields //GEN-LINE:MVDMethods
/** Called by the system to indicate that a command has been invoked on a particular displayable.//GEN-BEGIN:MVDCABegin * @param command the Command that ws invoked * @param displayable the Displayable on which the command was invoked */ public void commandAction(Command command, Displayable displayable) {//GEN-END:MVDCABegin // Insert global pre-action code here if (displayable == hauptForm) {//GEN-BEGIN:MVDCABody if (command == nextTextCommand) { nextSmsGeneration(); } else if (command == okCommand1) {//GEN-END:MVDCABody // Insert pre-action code here // Do nothing//GEN-LINE:MVDCAAction10 // Insert post-action code here } else if (command == exitCommand1) {//GEN-LINE:MVDCACase10 // Insert pre-action code here exitMIDlet();//GEN-LINE:MVDCAAction8 // Insert post-action code here }//GEN-BEGIN:MVDCACase8 }//GEN-END:MVDCACase8 // Insert global post-action code here }//GEN-LINE:MVDCAEnd
/** This method initializes UI of the application.//GEN-BEGIN:MVDInitBegin */ private void initialize() {//GEN-END:MVDInitBegin String tempSms = textAusDateiLesen("index.sms",0);
try { int startIndex = 0; int endIndex = 0; while((endIndex=tempSms.indexOf(",",startIndex)) > -1 ) { index.addElement(tempSms.substring(startIndex,endIndex)); startIndex = endIndex+1; } index.addElement(tempSms.substring(startIndex)); tempSms = null; memoryClean(); } catch (Exception ex) { ex.printStackTrace(); }
// Insert pre-init code here smsField = new TextField("SMS", null, 120, TextField.ANY);//GEN-BEGIN:MVDInitInit disp = getDisplay(); disp.setCurrent(get_hauptForm());//GEN-END:MVDInitInit // Insert post-init code here }//GEN-LINE:MVDInitEnd /** * This method should return an instance of the display. */ public Display getDisplay() {//GEN-FIRST:MVDGetDisplay return Display.getDisplay(this); }//GEN-LAST:MVDGetDisplay /** * This method should exit the midlet. */ public void exitMIDlet() {//GEN-FIRST:MVDExitMidlet getDisplay().setCurrent(null); destroyApp(true); notifyDestroyed(); }//GEN-LAST:MVDExitMidlet
/** This method returns instance for hauptForm component and should be called instead of accessing hauptForm field directly.//GEN-BEGIN:MVDGetBegin6 * @return Instance for hauptForm component */ public Form get_hauptForm() { if (hauptForm == null) {//GEN-END:MVDGetBegin6 // Insert pre-init code here hauptForm = new Form(null, new Item[] {smsField});//GEN-BEGIN:MVDGetInit6 hauptForm.addCommand(get_exitCommand1()); hauptForm.addCommand(get_okCommand1()); hauptForm.addCommand(get_nextTextCommand()); hauptForm.setCommandListener(this);//GEN-END:MVDGetInit6 // Insert post-init code here }//GEN-BEGIN:MVDGetEnd6 return hauptForm; }//GEN-END:MVDGetEnd6
public Command get_nextTextCommand() { if (nextTextCommand == null) { nextTextCommand = new Command("NextSMS", Command.OK, 1); } return nextTextCommand; }
/** This method returns instance for exitCommand1 component and should be called instead of accessing exitCommand1 field directly.//GEN-BEGIN:MVDGetBegin7 * @return Instance for exitCommand1 component */ public Command get_exitCommand1() { if (exitCommand1 == null) {//GEN-END:MVDGetBegin7 // Insert pre-init code here exitCommand1 = new Command("Exit", Command.EXIT, 1);//GEN-LINE:MVDGetInit7 // Insert post-init code here }//GEN-BEGIN:MVDGetEnd7 return exitCommand1; }//GEN-END:MVDGetEnd7
/** This method returns instance for okCommand1 component and should be called instead of accessing okCommand1 field directly.//GEN-BEGIN:MVDGetBegin9 * @return Instance for okCommand1 component */ public Command get_okCommand1() { if (okCommand1 == null) {//GEN-END:MVDGetBegin9 // Insert pre-init code here okCommand1 = new Command("Ok", Command.OK, 1);//GEN-LINE:MVDGetInit9 // Insert post-init code here }//GEN-BEGIN:MVDGetEnd9 return okCommand1; }//GEN-END:MVDGetEnd9
private void nextSmsGeneration() { try { Random r = new Random(); int size = index.size(); int elm = Integer.parseInt((index.elementAt(r.nextInt(size)))+""); long skip=0; for (int i = 0; i < elm; i++) { skip+=Long.parseLong(index.elementAt(i)+""); }
String tempSms = getSmsText("sms1.txt",skip, Long.parseLong(index.elementAt(elm)+"")); String sms2 = new String(tempSms.getBytes(),"windows-1251"); smsField.setMaxSize(sms2.length()); smsField.setString(sms2); } catch (Exception ex) { ex.printStackTrace(); }
disp.setCurrent(get_hauptForm()); } public void startApp() { nextSmsGeneration(); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public String textAusDateiLesen(String fileName, long skip) { String data=""; try { InputStream iStream = getClass().getResourceAsStream(fileName); InputStreamReader isReader = new InputStreamReader(iStream); int i=0; isReader.skip(skip); int symbol = isReader.read(); if (symbol != -1) { do { data+=((char)symbol); symbol = isReader.read(); } while (symbol != -1); } iStream.close(); } catch (Exception ex) { System.out.println("Error in textAusDateiLesen(): " + ex); } memoryClean(); return data; }
public void memoryClean() { memoryClean(false); }
public void memoryClean(boolean showLog) { if(showLog) { Log("====== MeM Status ======"); Log("Total Memory: " +Runtime.getRuntime().totalMemory()); Log("Freel Memory: " +Runtime.getRuntime().freeMemory()); }
System.gc(); System.gc();
try { Thread.sleep(1000); } catch(Exception sl_exc) { }
System.gc(); System.gc();
if(showLog) { Log("Total Memory: " +Runtime.getRuntime().totalMemory()); Log("Freel Memory: " +Runtime.getRuntime().freeMemory()); Log("===============\n"); } }
public void Log(String str) { System.out.println(str); }
public String getSmsText(String fileName, long skip, long getSymbols) { String data=""; try { InputStream iStream = getClass().getResourceAsStream(fileName); InputStreamReader isReader = new InputStreamReader(iStream); int i=0; isReader.skip(skip); int symbol = isReader.read(); i++; if (symbol != -1) { do { data+=((char)symbol); symbol = isReader.read(); } while (i++ != getSymbols); } iStream.close(); } catch (Exception ex) { System.out.println("Error in getSmsText(): " + ex); } memoryClean(); return data; }
}
|
|