Search Results

Search found 2 results on 1 pages for 'nii'.

Page 1/1 | 1 

  • Android: Using onStart() method in Bluetooth application

    - by Nii
    Hello, I am getting a nullpointer exception when my onStart() method is called. Here is the breakdown of my Android app: Opening the app brings a user to the homescreen: The user is then presented with the first 6 icons to choose from. When the user presses the "Sugar" icon it takes them to the SugarTabActivity. The SugarTabActivity is a Tabbed layout with two tabs. I'm concerned with the first tab. The first tab calls the getDefaultAdapter() method in its onCreate() method. Once it calls this, it checks if the bluetooth adapter is null on the phone, and if its null it shows a toast saying "Bluetooth is not available". This works just fine. Then I call the onStart() method. In the onStart() method I check if bluetooth is enabled, and if it isnt, then I start a new activity from the BluetoothAdapter enable bluetooth intent; otherwise, I start my bluetooth service. The exact error I'm getting is 04-19 00:44:45.674: ERROR/AndroidRuntime(225): Caused by: java.lang.NullPointerException 04-19 00:44:45.674: ERROR/AndroidRuntime(225): at com.nii.glucose.Glucose.onStart(Glucose.java:313). Heading Override public void onCreate(Bundle icicle) { super.onCreate(icicle); if(D) Log.d(TAG, "+++ ON CREATE +++"); setContentView(R.layout.glucose_layout); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if(mBluetoothAdapter==null){ Toast.makeText(this, "Bluetooth not available", Toast.LENGTH_LONG).show(); //finish(); return; } } Override public void onStart() { super.onStart(); if(D) Log.e(TAG, "++ ON START ++"); // If BT is not on, request that it be enabled. // setupChat() will then be called during onActivityResult if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); // Otherwise, setup the chat session } else { if (mGlucoseService == null) mGlucoseService = new BluetoothService(this, mHandler); } } @Override public synchronized void onResume(){ super.onResume(); if(D) Log.e(TAG,"==== ON RESUME ======"); // Performing this check in onResume() covers the case in which BT was // not enabled during onStart(), so we were paused to enable it... // onResume() will be called when ACTION_REQUEST_ENABLE activity returns. if (mGlucoseService != null) { // Only if the state is STATE_NONE, do we know that we haven't started already if (mGlucoseService.getState() == BluetoothService.STATE_NONE) { // Start the Bluetooth chat services mGlucoseService.start(); } } } @Override public synchronized void onPause(){ super.onPause(); //isActive.set(false); if(D) Log.e(TAG,"==== ON PAUSE ======"); } @Override public void onDestroy() { super.onDestroy(); // Stop the Bluetooth chat services if (mGlucoseService != null) mGlucoseService.stop(); if(D) Log.e(TAG, "--- ON DESTROY ---"); }

    Read the article

  • replaceAll() method using parameter from text file

    - by Herman Plani Ginting
    i have a collection of raw text in a table in database, i need to replace some words in this collection using a set of words. i put all the term to be replace and its substitutes in a text file as below min=admin lelet=lambat lemot=lambat nii=nih ntu=itu and so on. i have successfully initiate a variabel of File and Scanner to read the collection of the term and its substitutes. i loop all the dataset and save the raw text in a string in the same loop i loop all the term collection and save its row to a string name 'pattern', and split the pattern into two string named 'term' and 'replacer' in this loop i initiate a new string which its value is the string from the dataset modified by replaceAll(term,replacer) end loop for term collection then i insert the new string to another table in database end loop for dataset i do it manualy as below replaceAll("min","admin") and its works but its really something to code it manually for almost 2000 terms to be replace it. anyone ever face this kind of really something.. i really need a help now desperate :( package sentimenrepo; import javax.swing.*; import java.sql.*; import java.io.*; //import java.util.HashMap; import java.util.Scanner; //import java.util.Map; /** * * @author herman */ public class synonimReplaceV2 extends SwingWorker { protected Object doInBackground() throws Exception { new skripsisentimen.sentimenttwitter().setVisible(true); Integer row = 0; File synonimV2 = new File("synV2/catatan_kata_sinonim.txt"); String newTweet = ""; DB db = new DB(); Connection conn = db.dbConnect("jdbc:mysql://localhost:3306/tweet", "root", ""); try{ Statement select = conn.createStatement(); select.executeQuery("select * from synonimtweet"); ResultSet RS = select.getResultSet(); Scanner scSynV2 = new Scanner(synonimV2); while(RS.next()){ row++; String no = RS.getString("no"); String tweet = " "+ RS.getString("tweet"); String published = RS.getString("published"); String label = RS.getString("label"); clean2 cleanv2 = new clean2(); newTweet = cleanv2.cleanTweet(tweet); try{ Statement insert = conn.createStatement(); insert.executeUpdate("INSERT INTO synonimtweet_v2(no,tweet,published,label) values('" +no+"','"+newTweet+"','"+published+"','"+label+"')"); String current = skripsisentimen.sentimenttwitter.txtAreaResult.getText(); skripsisentimen.sentimenttwitter.txtAreaResult.setText(current+"\n"+row+"original : "+tweet+"\n"+newTweet+"\n______________________\n"); skripsisentimen.sentimenttwitter.lblStat.setText(row+" tweet read"); skripsisentimen.sentimenttwitter.txtAreaResult.setCaretPosition(skripsisentimen.sentimenttwitter.txtAreaResult.getText().length() - 1); }catch(Exception e){ skripsisentimen.sentimenttwitter.lblStat.setText(e.getMessage()); } skripsisentimen.sentimenttwitter.lblStat.setText(e.getMessage()); } }catch(Exception e){ skripsisentimen.sentimenttwitter.lblStat.setText(e.getMessage()); } return row; } class clean2{ public clean2(){} public String cleanTweet(String tweet){ File synonimV2 = new File("synV2/catatan_kata_sinonim.txt"); String pattern = ""; String term = ""; String replacer = ""; String newTweet=""; try{ Scanner scSynV2 = new Scanner(synonimV2); while(scSynV2.hasNext()){ pattern = scSynV2.next(); term = pattern.split("=")[0]; replacer = pattern.split("=")[1]; newTweet = tweet.replace(term, replacer); } }catch(Exception e){ e.printStackTrace(); } System.out.println(newTweet+"\n"+tweet); return newTweet; } } }

    Read the article

1