The file extension and read per mission issue Hi, I am in the problem about reading data fr om some new file extensions, the problem is fis.read() gets -1 from the first run wit

by 100town » Sat, 24 Oct 2009 19:39:16 GMT


Sponsored Links
 Hi,

I am in the problem about reading data from some new file extensions,
the problem is fis.read() gets -1 from the first run without and
exceptions being thrown. Check the code below:
String path = sdcard/wanshuiqianshan.lrc
java.io.FileInputStream fis = null;
                try{
                        fis= new java.io.FileInputStream(path);
                        int c=0;
                        StringBuffer sb=new StringBuffer();
                        while(((c=fis.read())!=-1)){
                                sb.append((char)c);
                        }
                        Log.e("INFO", "Here 1;
                        return sb.toString();
                }catch(Exception ioe){
                        Log.e("EROOR", "file: "+path, ioe);
                        return null;
                }finally{
                        try{
                                fis.close();
                        }catch(Exception e){
                        }
                }
If I change the file extension to xt everything is all right. I
debugged into the android source then the code running into the native
C code so not any clue was found.

I searched in the group. Only some discuss leads to the cycle about
mime-type and file extensions which cannot help me.
I guess it is a build-in security mechanism about the undefined file
extension types. Can anybody help? Thanks.


--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. AlertDialog error with events

I am new to java/android. I am trying to create an AlertDialog inside
my SmartApp class when an event is fired in my DataRobot class. I am
getting an error when doing this. The event is firing and calling the
function successfully in SmartApp, but when it gets to alert.show()
the following error is printed to logcat. Does anyone know what i am
doing wrong or a better way to implement what i am wanting? The
AlertDialog does not pop up on screen, logcat just complains about
something. Code and logcat output below:


    02-06 10:27:30.673: VERBOSE/SmartApp(276): data alert event caught
    02-06 10:27:31.013: WARN/System.err(276):
java.lang.RuntimeException: Can't create handler inside thread that
has not called Looper.prepare()
    02-06 10:27:31.042: WARN/System.err(276):     at
android.os.Handler.<init>(Handler.java:121)
    02-06 10:27:31.052: WARN/System.err(276):     at
android.view.ViewRoot.<init>(ViewRoot.java:231)
    02-06 10:27:31.052: WARN/System.err(276):     at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
    02-06 10:27:31.062: WARN/System.err(276):     at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
    02-06 10:27:31.082: WARN/System.err(276):     at
android.view.Window$LocalWindowManager.addView(Window.java:424)
    02-06 10:27:31.082: WARN/System.err(276):     at
android.app.Dialog.show(Dialog.java:241)
    02-06 10:27:31.102: WARN/System.err(276):     at
cpe495.smartapp.SmartApp$4.dataAlertReceived(SmartApp.java:80)
    02-06 10:27:31.102: WARN/System.err(276):     at
cpe495.smartapp.DataRobot.fireDataAlertEvent(DataRobot.java:96)
    02-06 10:27:31.122: WARN/System.err(276):     at
cpe495.smartapp.DataRobot.analyzeData(DataRobot.java:32)
    02-06 10:27:31.122: WARN/System.err(276):     at
cpe495.smartapp.SmartApp$2.dataReceivedReceived(SmartApp.java:66)
    02-06 10:27:31.133: WARN/System.err(276):     at
cpe495.smartapp.ConnectDevice.fireDataReceivedEvent(ConnectDevice.java:
71)
    02-06 10:27:31.133: WARN/System.err(276):     at
cpe495.smartapp.ConnectDevice.run(ConnectDevice.java:42)
    02-06 10:27:31.153: WARN/System.err(276):     at
java.lang.Thread.run(Thread.java:1096)

---


    // datarobot class
    public class DataRobot extends Activity {
        /* This class is for analyzing the data */
        private List _listeners = new ArrayList();
        private List<DataAlertListener> _listeners2 = new
ArrayList<DataAlertListener>();
        private SmartDataObject data;
        private int sI1;
        private int sI2;
        private float w1;
        private float w2;
        private float w3;
        private int hRB;
        private int hRVMin;
        private int hRVMax;

        public boolean analyzeData(SmartDataObject temp) {
                /* Analyze the data
                 * Returns true if data was successfully analyzed
                 * Returns false if an error occurred
                 */
                data = temp;
                if(data.getHeartRate()>290) {
                        fireDataAlertEvent();
                }
                fireDataAnalyzedEvent(data);
                return true; //for now this will always return true
        }

        public synchronized void addDataAnalyzedListener(DataAnalyzedListener
listener) {
                _listeners.add(listener);
        }
        public synchronized void
removeDataAnalyzedListener(DataAnalyzedListener listener) {
                _listeners.remove(listener);
        }
        private synchronized void fireDataAnalyzedEvent(SmartDataObject temp)
{
                DataAnalyzedEvent dRE = new DataAnalyzedEvent(this, temp);
                Iterator listeners = _listeners.iterator();
                while(listeners.hasNext()) {
                        
((DataAnalyzedListener)listeners.next()).dataAnalyzedReceived(dRE);
                }
        }
        public interface DataAnalyzedListener {
                public void dataAnalyzedReceived(DataAnalyzedEvent event);
        }



        public synchronized void addDataAlertListener(DataAlertListener
listener) {
                _listeners2.add(listener);
        }
        public synchronized void removeDataAlertListener(DataAlertListener
listener) {
                _listeners2.remove(listener);
        }
        private synchronized void fireDataAlertEvent() {
                DataAlertEvent dAE = new DataAlertEvent(this);
                Iterator listeners = _listeners2.iterator();
                while(listeners.hasNext()) {
                        
((DataAlertListener)listeners.next()).dataAlertReceived(dAE);
                }
        }
        public interface DataAlertListener {
                public void dataAlertReceived(DataAlertEvent event);
        }
    }



---

    public class DataAlertEvent extends EventObject {
        public DataAlertEvent(Object source) {
                super(source);
                // TODO Auto-generated constructor stub
        }
    }

---

    public class SmartApp extends Activity implements
OnSharedPreferenceChangeListener {
        TextView smartConnectionStatus;
        TextView testOutputView;
        Thread cThread;
        private ConnectDevice cD = new ConnectDevice();
        private DataRobot dR = new DataRobot();
        private DataBuilder dB = new DataBuilder();
        private DataSender dS = new DataSender();


        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.intro);

        final AlertDialog alert = new
AlertDialog.Builder(this).create();
                Log.v("SmartApp", "inside sendalert");
                //AlertDialog alert = new AlertDialog.Builder(this).create();
                Log.v("SmartApp", "after builder1");
                //{*filter*} {*filter*};
                //{*filter*} = ({*filter*}) 
getSystemService(Context.{*filter*}_SERVICE);
                //{*filter*}.vibrate(500);
                alert.setMessage("Testing alert dialog...");
                alert.setCancelable(false);
                alert.setButton("Ok", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                                // TODO Auto-generated method stub
                                dialog.cancel();
                        }
                });
                Log.v("SmartApp", "after builder2");
                //AlertDialog alert = builder.create();
                alert.setTitle("Title");

                cD.addDataReceivedListener(new DataReceivedListener() {
                        @Override
                        public void dataReceivedReceived(DataReceivedEvent 
event) {
                                // TODO Auto-generated method stub
                                dR.analyzeData(event.getData());
                        }
                });
                dR.addDataAlertListener(new DataAlertListener() {
                        @Override
                        public void dataAlertReceived(DataAlertEvent event) {
                                Log.v("SmartApp", "data alert event caught");
                                alert.show();
                        }
                });
        }

    }

-- 

2. lg ally android cant connect to blocks editor

what needs to be done to make this work?

-- 

3. How to save geolocation data on server.....

4. Where is best to start?

5. Emulator Uninstall to Previous One (2.3 to 2.2)

6. Problems with notification bar when called from a widget

7. Scrolling Problem