on Sunday, April 19, 2015



Hi All, I am trying to play a song that is in remote server and is in this link. You also can check the song. but as per what i have coded the song is not getting played from the remote server.




Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try{

mySong = new MediaPlayer();
mySong.setDataSource("http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3");
mySong.setAudioStreamType(AudioManager.STREAM_MUSIC);
mySong.prepareAsync();
mySong.start();

}
catch(Exception ee){
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(ee.getMessage());
}
finally{
mySong.reset();
mySong.release();
}
}
});



I've a TextView inside a CardView. Now the problem is when I use setText method on the TextView it's giving me nullPointerException. According to my tests textViewAuthor in the below code is null even after initializing it. Weird part is textViewName which is initialized the same way is not null. Why is it staying null even after assigning a view?



...
textViewName = (TextView)v.findViewById(R.id.textViewName); //not null
textViewAuthor = (TextView)v.findViewById(R.id.textViewAuthor); //NULL !!

if(textViewName == null)
Log.e("textViewName","null");
if(textViewAuthor == null)
Log.e("textViewAuthor","null");

Log.i("NAME", ebookName[position]); //not null
Log.i("AUTHOR", ebookAuthor[position]); //not null

holder.textViewName.setText(ebookName[position]);
holder.textViewAuthor.setText(ebookAuthor[position]);
...


Here's my layout code:



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">

<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clickable="true"
android:layout_weight="0.25">

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp">

<TextView
android:id="@+id/textViewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_margin="2dp" />

<TextView
android:id="@+id/textViewAuthor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_margin="2dp" />

</LinearLayout>
</android.support.v7.widget.CardView>

</LinearLayout>



How do I change keyboard.key background in onPress method when key is pressed and change it again when key is released? If you need any part of my code, please ask. Thanks in advance.




When I click register or login the app crash and get this errors: Error converting result java.lang.NullPointerException: lock == null Error parsing data org.json.JSONException: End of input at character 0 of


this is my code





import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class JSONParser {

static InputStream is = null;
static JSONObject jObj = null;
static String json = "";

// constructor
public JSONParser() {

}


public JSONObject getJSONFromUrl(final String url) {

// Making HTTP request
try {
// Construct the client and the HTTP request.
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);

// Execute the POST request and store the response locally.
HttpResponse httpResponse = httpClient.execute(httpPost);
// Extract data from the response.
HttpEntity httpEntity = httpResponse.getEntity();
// Open an inputStream with the data content.
is = httpEntity.getContent();

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

try {
// Create a BufferedReader to parse through the inputStream.
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
// Declare a string builder to help with the parsing.
StringBuilder sb = new StringBuilder();
// Declare a string to store the JSON object data in string form.
String line = null;

// Build the string until null.
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}

// Close the input stream.
is.close();
// Convert the string builder data to an actual string.
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}

// Try to parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}

// Return the JSON Object.
return jObj;

}


public JSONObject makeHttpRequest(String url, String method,
List params) {

// Haciendo la Petición HTTP
try {

// check for request method
if(method == "POST"){
// request method is POST
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));

HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();

}else if(method == "GET"){
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);

HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}

// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}

// return JSON String
return jObj;

}
}



thanks in advance




I want to design a layout having a checkbox similar to the image below


enter image description here


How do I achieve this.


I tried the following but it's not the result I want :



<CheckBox
android:id="@+id/chkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="On"
android:textColor="#000"
android:textSize="17sp" />



I have been searching around the web for some days and I have not found any known way/tool/library to disassemble APK file into source code from my app.


My goal is to get readable java files from the APK file only by using programmed functions of my app (or usable Android integrated features) but without external third-party solutions.


Dexdump have already been tried, but it didn’t output java files.


This step is crucial for my current educational project, any help will be highly appreciated. Thank you in advance and sorry for my bad English.




i want to extract all links of special webpage i try this:



URL url;
InputStream is = null;
BufferedReader br;
String line;
try {
url = new URL("http://www.stackoverflow.com");
is = url.openStream(); // throws an IOException
br = new BufferedReader(new InputStreamReader(is));

while ((line = br.readLine()) != null) {
if(line.contains("href="))
t1.setText(t1.getText()+line.trim());
}
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if (is != null) is.close();
} catch (IOException ioe) {
//exception
}
}


but it doesnt do anything... please help me if you have otherway please help