jeudi 13 août 2015

Why Cassandra cql query with hexadecimal literal works but textAsBinary does not?

I can do cassandra cql queries using hexadecimal literal, but when I try to use textAsBlob it does not work

For example the following works just fine:

cqlsh:sprich> SELECT * FROM "STOCK_CHECK_RTAM_ITEM_INDEX" WHERE key in (0x3631313230);

 key          | column1        | value

--------------+----------------+------------------------------------

0x3631313230 | 0x000330303100 | 0xf77374b5eced11e3a877005056b37d30

 0x3631313230 | 0x000330303200 | 0xf7757084eced11e3a877005056b37d30

 0x3631313230 | 0x000330303400 | 0xf7712ac8eced11e3a877005056b37d30

But the following two queries do not:

cqlsh:sprich> SELECT * FROM "STOCK_CHECK_RTAM_ITEM_INDEX" WHERE key in (textAsBlob("0x3631313230"));

Bad Request: line 1:84 missing EOF at ')'
text could not be lexed at line 1, char 15

cqlsh:sprich> SELECT * FROM "STOCK_CHECK_RTAM_ITEM_INDEX" WHERE key in (textAsBlob("3631313230"));
Bad Request: line 1:82 missing EOF at ')'
text could not be lexed at line 1, char 15

The following two queries do not give a syntax error but do not return the proper results as well:

cqlsh:sprich> SELECT * FROM "STOCK_CHECK_RTAM_ITEM_INDEX" WHERE key in (textAsBlob('0x3631313230'));

cqlsh:sprich> SELECT * FROM "STOCK_CHECK_RTAM_ITEM_INDEX" WHERE key in (textAsBlob('3631313230'));

Why is textAsBlob is not working? What mistake am I making in the proper use of textAsBlob?



via Chebli Mohamed

Opencv android app keeps crashing

I am trying to create a color recognition app for android. I want to check if a color is in range and measure the time it takes for that color to be in range. My problem is my app quits unexpectedly when it hit the "start test" button. I have no idea why its doing this, I believe I have set everything up right, but obviously I'm incorrect.

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SurfaceView;
import android.view.View;
import android.widget.TextView;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.JavaCameraView;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;


public class testActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {

private JavaCameraView mOpenCVCameraView;
Mat videoCamera;
Mat whiteArray;

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status){
        switch (status){
            case LoaderCallbackInterface.SUCCESS: {
                mOpenCVCameraView.enableView();
                break;
            }
            default:{
                super.onManagerConnected(status);
            }
        }
    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);
    mOpenCVCameraView = (JavaCameraView) findViewById(R.id.testPageBackground);
    mOpenCVCameraView.setVisibility(SurfaceView.INVISIBLE);
    mOpenCVCameraView.setCvCameraViewListener(this);
    getSupportActionBar().hide();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    //getMenuInflater().inflate(R.menu.menu_test, menu);
    mOpenCVCameraView.setCvCameraViewListener(this);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
public void onResume() {
    super.onResume();
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback);
}

public void onDestroy(){
    super.onDestroy();
    if (mOpenCVCameraView != null){
        mOpenCVCameraView.disableView();
    }
}

@Override
public void onCameraViewStarted(int width, int height) {
    videoCamera = new Mat(5,5,CvType.CV_8SC4);
    whiteArray = new Mat(5,5,CvType.CV_8SC4);
}

@Override
public void onCameraViewStopped() {
    videoCamera.release();
    whiteArray.release();
}

@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame)
{

    return inputFrame.rgba();
}

public void startTest (View view)
{
    View lagSquare = findViewById(R.id.lagSquare);
    TextView lagRating = (TextView) findViewById(R.id.lagRating);
    TextView lagTime = (TextView) findViewById(R.id.lagTime);
    double[] timeArray = new double[100]; // set array
    int testAmount;
    double rating;
    double lagStartTime;
    double lagEndTime;
    double lagTimeResult;
    for (testAmount = 0; testAmount < 100; testAmount++) //test loop
    {
        lagSquare.setBackgroundColor(Color.rgb(000,000,000)); //set lagSquare black
        lagStartTime = System.nanoTime(); //start lagTimer start
        lagSquare.setBackgroundColor(Color.rgb(255, 255, 255)); //set lagSquare white
        //set loop that checks for white
        Core.inRange(videoCamera, new Scalar(0, 0, 95), new Scalar(0, 0, 100), whiteArray);
        while (Core.countNonZero(whiteArray) == 0);
        {
        }
        lagEndTime = System.nanoTime(); //start lagTimer end
        lagTimeResult = (lagEndTime - lagStartTime);//stop lag timer
        timeArray[testAmount] = lagTimeResult; //put lagTimerResult in array


    }
    // min scan
    double minTimeArray = timeArray[0];
    for (int cnt=0; cnt < timeArray.length; cnt++ )
    {
        if (timeArray[cnt] < minTimeArray)
        {
            minTimeArray = timeArray[cnt];
        }
    }
    String minTimeArrayString = String.valueOf(minTimeArray);
    lagTime.setText(minTimeArrayString); //smallest number in timer array output to lagTime label

}

}

08-13 18:41:19.613  25826-25826/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: bluemage.systems.displaylatencytester, PID: 25826
    java.lang.IllegalStateException: Could not execute method of the activity
            at android.view.View$1.onClick(View.java:4020)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at android.view.View$1.onClick(View.java:4015)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
     Caused by: java.lang.NullPointerException: Attempt to read from field 'long org.opencv.core.Mat.nativeObj' on a null object reference
            at org.opencv.core.Core.countNonZero(Core.java:2053)
            at bluemage.systems.displaylatencytester.testActivity.startTest(testActivity.java:125)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at android.view.View$1.onClick(View.java:4015)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)



via Chebli Mohamed

Hello World program in Java not running

I started to learn Java with lynda.com.

The one of the first lessons tells how to write simple Hello World program. This lesson introduses us with two console commands same in Windows, Linux and Mac:

javac <path_to_source>
java <name_of_class>

I do all similar to code implemented in lesson. Here is it:

package com.lynda.jt;
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

Next you have to use these two commands to compile and run this program:

$ cd ~/HelloWorld
$ javac com/lynda/jt/HelloWorld.java
$ java com.lynda.jt.HelloWorld

But after running javac command it ends with error (I didn't save console output). Next I try to compile again but in other directory:

$ cd ~/HelloWorld/com/lynda/jt/
$ javac HelloWorld.java
$ cd ~/HelloWorld
$ java com.lynda.jt.HelloWorld
Error: Could not find or load main class com.lynda.lt.HelloWorld

Now its compiled and HelloWorld.class file appeared, but program still not running.

Next I delete .class file and do again:

$ cd ~/HelloWorld
$ javac com/lynda/jt/HelloWorld.java
$ java com.lynda.jt.HelloWorld
Hello World!

Now it's work but why? Previously I tried many other package diclarations:

com.lynda
com.lynda.javatraining
com.lynda.javatraining.hello_world
com.noq.jt

and others. But 99% of usesed paths lead to error messages. As to me it's just RANDOM.

Please clarify me this.



via Chebli Mohamed

putting data into array and then JTable

Referring to an earlier question i asked

lining up data in console output java

I wish to put my output in an array so that i can then further put this into a JTable

The extract for my code so far is, i am currently printing out the output to the console.

String assd = null;
String eventy = null;
String assdFT = null;


for (int i = 0; i < list.getLength(); i++) {
Element element = (Element)list.item(i);
String nodeName = element.getNodeName();

switch (nodeName) {
case "assd":
assd = element.getChildNodes().item(0).getNodeValue();



break;
case "eventy":
eventy = element.getChildNodes().item(0).getNodeValue(); 

break;
case "assdFT":

assdFT = element.getChildNodes().item(0).getNodeValue(); 
                 break;

System.out.printf("%-30s  %-20s  %-20s  %-50s  %-20s  %-20s  %-20s  %-20s  %-30s  %s%n", assd,  eventy,assdFT);

//my attempt so far but how do i add each element assd,eventy and assdFT        
Object[][] data = new Object[1000][10];    
for (int r=0; r<data.length; r++) {
for (int c=0; c<data[r].length; c++) {
 data[r][c]=assd;//your value
} 



via Chebli Mohamed

Storing parsed Rss items within SQLite

As my first Android project I'm trying to make an RSS reader app in which Listview items can be saved to SQLite, allowing them to be read offline. However, when trying to return news titles in a listView using a query with SimpleCursorAdapter, the listview displays the text "title", rather than the actual title of the news.

This seems to suggest that the items are not being stored to the database, or that the content values are not being properly assigned.

Can anybody see where i might be going wrong?

Thanks in advance!

RssItem.java

public class RssItem {

protected String _id;
public String title;
protected String link;
protected String page;
protected String completeTextLink;
protected String mainBody;


public String get_id() {
    return _id;
}

public void set_id(String _id) {
    this._id = _id;
}

//Title get/set
public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}


//Link get/set
public String getLink() {
    return link;
}

public void setLink(String link) {
    this.link = link;
}


//CompleteTextLink get/set
public String getCompleteTextLink() {
    return completeTextLink;
}

public void setCompleteTextLink(String completeTextLink) {
    this.completeTextLink = completeTextLink;
}


//MainBody get/set
public String getMainBody() {
    return mainBody;
}

public void setMainBody(String mainBody) {
    this.mainBody = mainBody;
}


//Page get/set
public String getPage() {
    return page;
}

public void setPage(String page) {
    this.page = page;
}

@Override
public String toString() {
    return title;
}}

MainActivity.java

public class MainActivity extends Activity {

private MainActivity local;
private DatabaseHandler db;

//Method to create main application view
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //set view
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);


    //**************************create a button to move to the user's saved feeds screen*****************************

    Button myFeedsButton = (Button) findViewById(R.id.myFeedsButton);
    myFeedsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v)
        {
            startActivity(new Intent(MainActivity.this, MyFeedsScreen.class));
        }
    });

    //***************************************************************************************************************

    //Create new instance of database handler
    db = new DatabaseHandler(this);
    //set local ref to this activity
    local = this;

    GetRSSDataTask task = new GetRSSDataTask();

    //start download Rss task - execute method calls the
    task.execute("http://ift.tt/1jZeUCj");

    //debug thread name
    Log.d("RssReaderApp", Thread.currentThread().getName());
}

//*******************************************************************************************************************

private class GetRSSDataTask extends AsyncTask<String, Void, List<RssItem>>
{
    @Override
    protected List<RssItem> doInBackground(String... urls) {

        //debug task thread name
        Log.d("RssReaderApp", Thread.currentThread().getName());

        try {
            //create a new reader
            RssReader rssReader = new RssReader(urls[0]);

            //Parse RSS, get items
            return rssReader.getItems();
        } catch (Exception e) {
            Log.e("RssReaderApp", e.getMessage());
        }

        return null;

    }//doInBackground


    //is invoked on UI thread after background tasks are complete.
    // Results of background task are passed here as a parameter
    @Override
    protected void onPostExecute(List<RssItem> result)
    {
        //Gets listview from main.xml
        final ListView listItems = (ListView) findViewById(R.id.listMainView);

        //Creates a new list adapter - displays an array of strings in listview
        ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>(local, android.R.layout.simple_list_item_1, result);
        //Set list adapter for listView
        listItems.setAdapter(adapter);

        //OnItemClick listener set to allow user to access content from title
        listItems.setOnItemClickListener(new ListListener(result, local));



        //*******************************LONG CLICK FUNCTIONALITY******************************************
        //Set new long click listener which should allow item to be stored to db
        listItems.setLongClickable(true);
        listItems.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

                try {

                    db.open();
                    RssItem item = new RssItem();
                    item.title = "title";
                    item.link = "link";
                    item.completeTextLink ="completeTextLink";
                    item.page = "page";

                    db.insertRssItem(item);

                   db.close();

                } catch (SQLException e)
                    {
                        e.printStackTrace();
                    }


                Toast.makeText(getBaseContext(), "Item saved in My Feeds!", Toast.LENGTH_SHORT).show();
                return true;


            }
        });

        }//onPostExecute
    }}//class

DatabaseHandler.java

public class DatabaseHandler extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "news_db";
public static SQLiteDatabase db;
private static final int DATABASE_VERSION = 32;
protected static final String TABLE_NEWS = "news";
private static final String TAG = "TAG";
private static final String TAG1 = "TAG1";
static String columnTitle = "title";
protected static final String _id = "_id";


//Methods for tables
public DatabaseHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {

    String CREATE_TABLE_NEWS = "CREATE TABLE " + TABLE_NEWS + "(_id VARCHAR, title TEXT, link TEXT, completeTextLink TEXT, mainBody Text, page TEXT)";
    db.execSQL(CREATE_TABLE_NEWS);
    Log.w(TAG, "Database has been created");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_NEWS);
    onCreate(db);
}

public void open() throws SQLException {
    db = this.getWritableDatabase();
}


//Method to insert new rssItem object to the database

public void insertRssItem(RssItem rssItem) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put("_id", rssItem._id);
    contentValues.put("title", rssItem.title);
    contentValues.put("link", rssItem.link);
    contentValues.put("mainBody", rssItem.mainBody);
    contentValues.put("completeTextLink", rssItem.completeTextLink);
    contentValues.put("page", rssItem.page);

    db.insert(TABLE_NEWS, "title", contentValues);
    Log.d(TAG1, "ITEM SAVED IN DATABASE!!!");

}//insert item method


//Method to return all news for a given item
public List<RssItem> getAllNewsForItem(String page) {
    List<RssItem> SavedNewsList = new ArrayList<RssItem>();
    Cursor cursor = db.rawQuery("select _id, completeTextLink, title, link, mainBody, page" +
            " FROM " + TABLE_NEWS + " where page = ?", new String[]{page});

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        RssItem rssItem = new RssItem();
        rssItem._id = cursor.getString(0);
        rssItem.completeTextLink = cursor.getString(1);
        rssItem.title = cursor.getString(2);
        rssItem.link = cursor.getString(3);
        rssItem.mainBody = cursor.getString(4);
        rssItem.page = page;

        SavedNewsList.add(rssItem);
        cursor.moveToNext();
    }
    cursor.close();
    return SavedNewsList;
}


//get data from database for listview
public Cursor getData() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_NEWS, null);
    return cursor;
}}

MyFeedsScreen.java

public class MyFeedsScreen extends ListActivity {

DatabaseHandler dbHandler;
SimpleCursorAdapter dataAdapter;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_feeds_screen);
    dbHandler = new DatabaseHandler(MyFeedsScreen.this);
    displayList();
}

public void displayList() {
    dbHandler.getWritableDatabase();
    dbHandler = new DatabaseHandler(this);

    Cursor cursor = dbHandler.getData();
    String from[] = new String[]{dbHandler.columnTitle};
    int to[] = new int[]{R.id.textView1};
    dataAdapter = new SimpleCursorAdapter(this, R.layout.row_item, cursor, from, to, 0);

    ListView lv = getListView();
    lv.setAdapter(dataAdapter);


}}



via Chebli Mohamed

Xpath in for loop with using Java

I wonder that


for(int k=1; k<4; k++){
    String  elem1 = driver.findElement(By.xpath("/html/body/div[4]/div/div/div[2]/div/div/div/div[3]/div[2]/div[2]/div[2]/ul[1]/li[6]/div/ul/li/div/a[k]" + k)).getAttribute("innerHTML");
    //String  elem2 = driver.findElement(By.xpath("/html/body/div[4]/div/div/div[2]/div/div/div/div[3]/div[2]/div[2]/div[2]/ul[1]/li[6]/div/ul/li/div/a[2]")).getAttribute("innerHTML");
    //String  elem3 = driver.findElement(By.xpath("/html/body/div[4]/div/div/div[2]/div/div/div/div[3]/div[2]/div[2]/div[2]/ul[1]/li[6]/div/ul/li/div/a[3]")).getAttribute("innerHTML");



    System.out.println(elem1);
    //System.out.println(elem2);
    //System.out.println(elem3);

    Thread.sleep(3000);
    double value = Double.parseDouble(elem1);
    System.out.println(value);
    }


As you can see in "String elem1" line; i try to pass value k into xpath, but it doesnt work. How can i do that? I need to increase the value of k because as you can see in comments line it goes; 1-2-3-4....-78... Please help me, thank you all :)



via Chebli Mohamed

Java - Xuggle Crashing on Windows 7 64 bit

I am using xuggle-xuggler-5.4.jar file in my Java application (to extract media information like duration, bitrate etc), and it crashes the whole application at "container.open()". It generates a log file containing the following message:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000011226520, pid=15980, tid=16324
#
# JRE version: Java(TM) SE Runtime Environment (7.0_45-b18) (build 1.7.0_45-b18)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.45-b08 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [xuggle7723496972795585954.dll+0x736520]
---------

Can you provide jar file for xuggle 5.5 version. If not please suggest a good API / framework which provides media information.

Thanks,



via Chebli Mohamed