Thursday, May 9, 2013

[android help] Android, List Adapter returns wrong position in getView


I have found a mysterious problem that may be a bug! I have a list in my fragment. Each row has a button. List shouldn't respond to click however buttons are clickable.


In order to get which button has clicked I have created a listener and implement it in my fragment. This is the code of my adapter.



public class AddFriendsAdapter extends BaseAdapter {

public interface OnAddFriendsListener {
public void OnAddUserClicked(MutualFriends user);
}

private final String TAG = "*** AddFriendsAdapter ***";

private Context context;
private OnAddFriendsListener listener;
private LayoutInflater myInflater;
private ImageDownloader imageDownloader;
private List userList;

public AddFriendsAdapter(Context context) {
this.context = context;
myInflater = LayoutInflater.from(context);

imageDownloader = ImageDownloader.getInstance(context);
}

public void setData(List userList) {
this.userList = userList;

Log.i(TAG, "List passed to the adapter.");
}

@Override
public int getCount() {
try {
return userList.size();
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}

@Override
public Object getItem(int position) {
return null;
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;

if (convertView == null) {
convertView = myInflater.inflate(R.layout.list_add_friends_row, null);
holder = new ViewHolder();

Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/ITCAvantGardeStd-Demi.ttf");
holder.tvUserName = (TextView) convertView.findViewById(R.id.tvUserName);
holder.tvUserName.setTypeface(font);
holder.ivPicture = (ImageView) convertView.findViewById(R.id.ivPicture);
holder.btnAdd = (Button) convertView.findViewById(R.id.btnAdd);
holder.btnAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e(TAG, "Item: " + position);
listener.OnAddUserClicked(userList.get(position));
}
});

convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

holder.tvUserName.setText(userList.get(position).getName());
imageDownloader.displayImage(holder.ivPicture, userList.get(position).getPhotoUrl());

return convertView;
}

public void setOnAddClickedListener(OnAddFriendsListener listener) {
this.listener = listener;
}

static class ViewHolder {
TextView tvUserName;
ImageView ivPicture;
Button btnAdd;
}
}


When I run the app, I can see my rows however since my list is long and has over 200 items when i goto middle of list and click an item then returned position is wrong (it's something like 7, sometimes 4 and etc.).


Now what is the mystery? If I active on item listener of list from my fragment and click on row then correct row position will be displayed while on that row if I click on button then wrong position will be displayed.



listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
Log.e(TAG, "item " + position + " clicked.");
}
});


Result in logcat:



05-09 10:22:25.228: E/AddFriendsFragment(20296): item 109 clicked.
05-09 10:22:34.453: E/*** AddFriendsAdapter ***(20296): Item: 0


Any suggestion would be appreciated. Thanks



.

stackoverflow.comm

[android help] getting user location with a button click on google map


I am trying to find the user location with latitude and longitude. Is it possible to add a button to save the location (lat, long) and jump into another page? Or maybe get the image of the user location on the map. Do help me out on what to do. Thanks.



package mp.memberuse;

import android.app.Dialog;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class Map extends FragmentActivity {

GoogleMap googleMap;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.map);

// Getting Google Play availability status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

// Showing status
if(status!=ConnectionResult.SUCCESS)
{ // Google Play Services are not available

int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();

}
else
{ // Google Play Services are available

// Getting reference to the SupportMapFragment of activity_main.xml
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

// Getting GoogleMap object from the fragment
googleMap = fm.getMap();

// Enabling MyLocation Layer of Google Map
googleMap.setMyLocationEnabled(true);

// Getting LocationManager object from System Service LOCATION_SERVICE
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

// Creating a criteria object to retrieve provider
Criteria criteria = new Criteria();

// Getting the name of the best provider
String provider = locationManager.getBestProvider(criteria, true);

// Getting Current Location
Location location = locationManager.getLastKnownLocation(provider);

LocationListener locationListener = new LocationListener()
{
public void onLocationChanged(Location location)
{
// redraw the marker when get location update.
drawMarker(location);
}

@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub

}

@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub

}

@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub

}
};

if(location!=null)
{
//PLACE THE INITIAL MARKER
drawMarker(location);
}
locationManager.requestLocationUpdates(provider, 20000, 0, locationListener);
}
}
private void drawMarker(Location location)
{
googleMap.clear();
LatLng currentPosition = new LatLng(location.getLatitude(),
location.getLongitude());
googleMap.addMarker(new MarkerOptions().position(currentPosition).snippet("Lat:" + location.getLatitude() + "Lng:"+ location.getLongitude()).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.title("ME"));
}
Location location;
LatLng currentPosition = new LatLng(location.getLatitude(),location.getLongitude());
String myLocation = currentPosition.toString();

void saveLoc(){
if ( myLocation!=null){
// save Location in SharedPreference or a Database here
SharedPreferences prefs = getSharedPreferences("myPreferences",Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("myLocation", myLocation);
editor.commit();
// Start new activity
Intent intent = new Intent(Map.this, SendMessage.class);
startActivity(intent);
}
}


Logcat.txt



05-09 02:01:54.280: D/dalvikvm(508): GC_EXTERNAL_ALLOC freed 51K, 53% free 2576K/5379K, external 3129K/3266K, paused 72ms
05-09 02:01:57.891: W/KeyCharacterMap(508): No keyboard for id 0
05-09 02:01:57.891: W/KeyCharacterMap(508): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
05-09 02:02:34.450: W/KeyCharacterMap(508): No keyboard for id 0
05-09 02:02:34.450: W/KeyCharacterMap(508): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
05-09 02:02:34.490: D/dalvikvm(508): GC_CONCURRENT freed 1486K, 58% free 3019K/7111K, external 3430K/4246K, paused 6ms+4ms
05-09 02:02:46.381: I/dalvikvm(508): Total arena pages for JIT: 11
05-09 02:02:47.931: D/dalvikvm(508): GC_CONCURRENT freed 1315K, 59% free 2950K/7111K, external 3430K/4246K, paused 5ms+4ms
05-09 02:02:48.281: D/AndroidRuntime(508): Shutting down VM
05-09 02:02:48.281: W/dalvikvm(508): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-09 02:02:48.300: E/AndroidRuntime(508): FATAL EXCEPTION: main
05-09 02:02:48.300: E/AndroidRuntime(508): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{mp.memberuse/mp.memberuse.Map}: java.lang.NullPointerException
05-09 02:02:48.300: E/AndroidRuntime(508): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
05-09 02:02:48.300: E/AndroidRuntime(508): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-09 02:02:48.300: E/AndroidRuntime(508): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-09 02:02:48.300: E/AndroidRuntime(508): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-09 02:02:48.300: E/AndroidRuntime(508): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 02:02:48.300: E/AndroidRuntime(508): at android.os.Looper.loop(Looper.java:123)
05-09 02:02:48.300: E/AndroidRuntime(508): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-09 02:02:48.300: E/AndroidRuntime(508): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 02:02:48.300: E/AndroidRuntime(508): at java.lang.reflect.Method.invoke(Method.java:507)
05-09 02:02:48.300: E/AndroidRuntime(508): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-09 02:02:48.300: E/AndroidRuntime(508): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-09 02:02:48.300: E/AndroidRuntime(508): at dalvik.system.NativeStart.main(Native Method)
05-09 02:02:48.300: E/AndroidRuntime(508): Caused by: java.lang.NullPointerException
05-09 02:02:48.300: E/AndroidRuntime(508): at mp.memberuse.Map.(Map.java:114)
05-09 02:02:48.300: E/AndroidRuntime(508): at java.lang.Class.newInstanceImpl(Native Method)
05-09 02:02:48.300: E/AndroidRuntime(508): at java.lang.Class.newInstance(Class.java:1409)
05-09 02:02:48.300: E/AndroidRuntime(508): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-09 02:02:48.300: E/AndroidRuntime(508): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
05-09 02:02:48.300: E/AndroidRuntime(508): ... 11 more
05-09 02:02:55.531: I/Process(508): Sending signal. PID: 508 SIG: 9


.

stackoverflow.comm

[android help] Android-NDK: Fatal signal 11 (SIGSEGV) on Windows 64 only

Android-NDK: Fatal signal 11 (SIGSEGV) on Windows 64 only - Stack Overflow








Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















When I run the project on my Mac everything is fine. The same project run on Windows 64 I crash upon start.


Both use NDK8e. How can I find out what is the difference?


Windows 64



05-09 04:25:51.310: D/dalvikvm(16908): Shared lib '/data/data/com.evotegra.aCoDriver/lib/libjsqlite.so' already loaded in same CL 0x4219e688
05-09 04:25:51.335: A/libc(16908): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 16908 (tegra.aCoDriver)


Mac



05-09 04:49:09.070: D/dalvikvm(307): Shared lib '/data/data/com.evotegra.aCoDriver/lib/libjsqlite.so' already loaded in same CL 0x4219d5f8
05-09 04:49:40.735: V/SoundPoolThread(27591): beginThread















Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.










default







.

stackoverflow.comm

[General] SOS, Need Help to find my phone!!!


Who can help me solve my problem.
My LG E730 smartphone is have in someones of my friends without a sim card but with an internet connection over WiFi.
How to calculate from where my smartphone connecting to internet, and how to find IP address of the phone?
P.S. I can install any application on it over Google Play in my account using browser!

What app can help me to track where my smartphone is??



.

forum.xda-developers.com

[General] Tab 2 / general Questions


Hi, I have some questions. I would appreciate any assistance

Samsung Tab 2 (7.0, 3113 Wifi with IR)

Android vers 4.1.1 (afaik latest for this device)

1) Could anyone recommend a case? I need something that can flip (prefer a magnet based lock). It needs to be able to take massive impacts (ie. drop from onto cement from 2 meters) from EVERY angle, including corners. I also need it real quick (within 12 days) - so big department stores are good, and Amazon Prime is good (I live in Canada)

2) Is there any way to adjust screen dim time?

3) Is there any way to have the screen automatically turn on/off using the sensors? Namely, the light and proximity sensors. Ex. proximity sensor: IF object is detected within 2 cm continuously for 5 seconds, shut off screen. IF object is removed, turn screen on. I had a Nexus 7 with a magnetic flip case, in which the Nexus 7 would automatically turn on when the flap was opened, and turn off when the flap was closed, as sensed by its magnetometer.

4) Could I get detailed instructions into the installation of Cyanogenmod? What exactly is it good for? Any other BIOSes worth looking into?

5) A suggestion for a fast PDF reader? I need something that will process large, coloured images very quickly (a large sized travel book).

6) Any tweaks to maximize speed? I just bought it 2 days ago and its not as fast as I'd like even out of the box.

7) Is there any way to get better camera quality? I want to use it in the place of a discrete camera (personal reasons).

Thanks in advace. Any help with even one of the questions would be great.



.

forum.xda-developers.com

[android help] How to clickable list's row and button in row in listview?


I am using a listview in my Android program.


I have row. 1) i have custom row in button and i want to when click button then open the alert box and this row clicked then open the new activity but Only one button clicked not row clicked . how to possible in this case. my code in below.


Thank you.



public class AlMessagesAdapter extends ArrayAdapter {

private LayoutInflater inflator;
private ArrayList userlist;

public AlMessagesAdapter(Activity context, ArrayList list) {
super(context, R.layout.custom_list, list);

this.userlist = list;
inflator = context.getLayoutInflater();
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

ViewHolder holder = null;
if (convertView == null) {
convertView = inflator.inflate(R.layout.custom_list, null);
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.tvName);
holder.date_cr = (TextView) convertView.findViewById(R.id.tvDate);
holder.img = (ImageView)convertView.findViewById(R.id.ivIcon);
holder.tokenBtn = (Button)convertView.findViewById(R.id.tokenBtn);
convertView.setTag(holder);
convertView.setTag(R.id.tvName, holder.title);
convertView.setTag(R.id.tvDate, holder.date_cr);
convertView.setTag(R.id.ivIcon,holder.img);
convertView.setTag(R.id.tokenBtn,holder.tokenBtn);

} else {
holder = (ViewHolder) convertView.getTag();
}

String token = userlist.get(position).getToken();

Log.v("MessageList", "token:" + token);

token = token.substring(0,token.length()-3);

holder.title.setText(userlist.get(position).getName()+"("+token+")");

String type_data = userlist.get(position).getType().toString();

if((type_data.equals("text")) || (type_data.equals("photo")))
{
Log.v("log", " if text photo ");
holder.date_cr.setText(userlist.get(position).getType()+":Received "+userlist.get(position).getCreated_date());
holder.tokenBtn.setVisibility(View.VISIBLE);
list.setItemsCanFocus(true);
}
else if(type_data.equals("out"))
{
Log.v("log", " else out ");
holder.date_cr.setText(userlist.get(position).getType()+":Sent "+userlist.get(position).getCreated_date());
holder.tokenBtn.setVisibility(View.GONE);
}

if(type_data.equals("text"))
{
Log.v("log", " if text ");
holder.img.setBackgroundResource(R.drawable.chatmessage);

}
else if(type_data.equals("photo"))
{
Log.v("log", " ese if photo ");
holder.img.setBackgroundResource(R.drawable.photomessage);

}
else if(type_data.equals("out"))
{
Log.v("log", " ese if out ");
holder.img.setBackgroundResource(R.drawable.outmessafe);
}


if(position%2==0)
{
convertView.setBackgroundResource(R.drawable.whitebackground);
}
else
{
convertView.setBackgroundResource(R.drawable.greybackground);
}

holder.tokenBtn.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.v("log_tag"," token button clicked");
}
});


return convertView;
}

class ViewHolder {
protected ImageView img;
protected TextView date_cr;
protected TextView title;
protected Button tokenBtn;
}
}


and list click event in below::



list.setOnItemLongClickListener(new OnItemLongClickListener() {

@Override
public boolean onItemLongClick(AdapterView arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub

msg = userLIstArray.get(position).getMessage();
token = userLIstArray.get(position).getToken();
type = userLIstArray.get(position).getType();
int msgId = userLIstArray.get(position).getMessageid();
token = token.substring(0,token.length()-3);
int token_value = Integer.parseInt(token) * 1000;

if(type.equals("text"))
{
Log.v("log", " if in text to Display " + msg + " token "+token);
Intent i = new Intent(MessagesList.this,DisplayPopupActivity.class);
i.putExtra("msg", msg);
i.putExtra("token", token);
i.putExtra("msgid", msgId);
startActivity(i);

}
else if(type.equals("photo"))
{
Log.v("log", " else in IMage to Display " + msg + " token "+token);

Log.v("log","token "+token+" type "+type + " position "+position + "msgId "+ msgId);

Intent i = new Intent(MessagesList.this,DisplayImageActivity.class);
i.putExtra("imgData", msg);
i.putExtra("token", token);
i.putExtra("msgid", msgId);
startActivity(i);

//Log.v("log"," Message" +message);
//Toast.makeText(AllMessageActivity.this, "Message "+message, Toast.LENGTH_LONG).show();
}

return false;
}
});
}


.

stackoverflow.comm

[android help] how to use simple getter and setter with android


I have a class country with an arraylist that stores countries. I have created a get and set to add and get items from specified indexes from the array list but i wont work. Whenever i call an index from the arraylist i get an out of bounds exception because the array is empty or at least seems to be.



public class country extends Application {

public ArrayList countryList = new ArrayList();
public String Name;
public String Code;
public String ID;

public country()
{

}

public country(String name, String id, String code)
{
this.Name = name;
this.ID = id;
this.Code = code;
}

public void setCountry(country c)
{
countryList.add(c);
}

public country getCountry(int index)
{
country aCountry = countryList.get(index);
return aCountry;
}


to call the setter i use.



country ref = new country();

ref.setCountry(new country (sName, ID, Code));


then when i want to get an index



String name = ref.countryList.get(2).Name;


i have done the same thing but used a local arraylist and it populated fine and i was able to display the names so the datasource isnt the problem its whatever im doing wrong setting and getting the data inside the arraylist in the country class



.

stackoverflow.comm

[android help] Fragment and Activity Issues


I am trying to create a simple set of screens in an android app. The app begins with a menu screen with buttons. After a choice is made I then want to launch an activity built with 2 fragments (one for player 1 and another for player 2). However when I try and start the activity with the fragments I get an error in the android emulator.


Here is my code so far:


The main menu code



import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;

public class MainMenuActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
}

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

// load up 1v1 duel activity
public void beginRegularDuel(View view)
{
Intent intent = new Intent(this, OneVsOneDuelActivity.class);

startActivity(intent);
}

}


The 1v1 Duel Code:



package com.PigRam.magichelper;
import android.app.Activity;
import android.os.Bundle;

public class OneVsOneDuelActivity extends FragmentActivity{

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);

setContentView(R.layout.one_vs_one_view);
}
}


The Player One fragment code:



package com.PigRam.magichelper;

import android.annotation.TargetApi;
import android.app.Fragment;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class PlayerOneDuelFragment extends Fragment {

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.one_vs_one_view, container, false);
}
}


And Player Two:



package com.PigRam.magichelper;

import android.annotation.TargetApi;
import android.app.Fragment;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class PlayerTwoDuelFragment extends Fragment{

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.one_vs_one_view, container, false);
}
}


And layout for main menu



xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >

android:id="@+id/main_menu_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_menu_title"
android:textSize="50sp" />

android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >

android:id="@+id/regular_duel"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="@string/regular_duel"
android:onClick="beginRegularDuel" />

android:id="@+id/two_headed_dragon"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/two_headed_dragon" />






And the Duel Screen layout




android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:baselineAligned="false">

android:id="@+id/player_one_fragment"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"/>

android:id="@+id/player_two_fragment"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />



Also the manifest




package="com.PigRam.magichelper"
android:versionCode="1"
android:versionName="1.0" >

android:minSdkVersion="8"
android:targetSdkVersion="17" />

android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

android:label="@string/app_name" >







android:label="@string/app_name">







And last but not least here is the error log:


05-09 09:40:18.696: D/gralloc_goldfish(1521): Emulator without GPU emulation detected. 05-09 09:40:22.746: D/AndroidRuntime(1521): Shutting down VM 05-09 09:40:22.756: W/dalvikvm(1521): threadid=1: thread exiting with uncaught exception (group=0x40a71930) 05-09 09:40:22.916: D/dalvikvm(1521): GC_CONCURRENT freed 191K, 11% free 2634K/2956K, paused 75ms+122ms, total 303ms 05-09 09:40:22.926: E/AndroidRuntime(1521): FATAL EXCEPTION: main 05-09 09:40:22.926: E/AndroidRuntime(1521): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.PigRam.magichelper/com.PigRam.magichelper.OneVsOneDuelActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.app.ActivityThread.access$600(ActivityThread.java:141) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.os.Handler.dispatchMessage(Handler.java:99) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.os.Looper.loop(Looper.java:137) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.app.ActivityThread.main(ActivityThread.java:5041) 05-09 09:40:22.926: E/AndroidRuntime(1521): at java.lang.reflect.Method.invokeNative(Native Method) 05-09 09:40:22.926: E/AndroidRuntime(1521): at java.lang.reflect.Method.invoke(Method.java:511) 05-09 09:40:22.926: E/AndroidRuntime(1521): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 05-09 09:40:22.926: E/AndroidRuntime(1521): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 05-09 09:40:22.926: E/AndroidRuntime(1521): at dalvik.system.NativeStart.main(Native Method) 05-09 09:40:22.926: E/AndroidRuntime(1521): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 05-09 09:40:22.926: E/AndroidRuntime(1521): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.app.Activity.setContentView(Activity.java:1881) 05-09 09:40:22.926: E/AndroidRuntime(1521): at com.PigRam.magichelper.OneVsOneDuelActivity.onCreate(OneVsOneDuelActivity.java:13) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.app.Activity.performCreate(Activity.java:5104) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 05-09 09:40:22.926: E/AndroidRuntime(1521): ... 11 more 05-09 09:40:22.926: E/AndroidRuntime(1521): Caused by: java.lang.ClassCastException: com.PigRam.magichelper.PlayerOneDuelFragment cannot be cast to android.support.v4.app.Fragment 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.support.v4.app.Fragment.instantiate(Fragment.java:394) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.support.v4.app.Fragment.instantiate(Fragment.java:369) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272) 05-09 09:40:22.926: E/AndroidRuntime(1521): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676) 05-09 09:40:22.926: E/AndroidRuntime(1521): ... 21 more


Sorry for all the code but this is really bugging me. I am new to Android programming so please help me out!


Thanks.



.

stackoverflow.comm

[android help] App crashes on mobile device after using ProGuard

java - App crashes on mobile device after using ProGuard - Stack Overflow








Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















After successfully using ProGuard on my application, it crashes on the startup on my mobile device. I use standard configuration of proguard: ${sdk.dir}/tools/proguard/proguard-android.txt


And logcat says something like this: E/AndroidRuntime(13441): at packagename.q.doInBackground(Unknown Source)


And then some App crashed errors etc.


Why does it not find my Source in doInBackground? Its a simple AsyncTask. Can anyone help me?



















Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.










lang-java







.

stackoverflow.comm

[android help] android.os.NetworkOnMainThreadException with a AsyncTask


I'm trying to connect a socket with Android. I know that you can't open network-connections from MainThread. I have created an AsyncTask to do it. I have created and private class inside of the main class, I have seen some examples on internet about that.


Could someone help me about what it's wrong?? I guess that it's a error in the way I'm trying to connect because I have connected to the server with a normal Java class. I have edited the manisfest to give the necessary permissions.


If someone has any advise about a better way to do it, it would be great.



public class MainActivity extends Activity {

private ObjectInputStream input;
private ObjectOutputStream output;
private Button buttonCreateRoom;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

buttonCreateRoom = (Button)findViewById(R.id.buttonCreate);


//buttons
buttonCreateRoom.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {
onClickButton(ConstantsRooms.CREATE_ROOM);
}
});


}

private void onClickButton(int numberButton){
RequestMessage request = null;

switch (numberButton) {
....
}

AsyncButtons asyncButtons = new AsyncButtons();
asyncButtons.execute(request);

}


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




//Botones
private class AsyncButtons extends AsyncTask {
private Socket socket;

@Override
protected Void doInBackground(RequestMessage... params) {
RequestMessage request;
ResponseMessage response;
Void v = null;
try{

request = params[0];
output.writeObject(request);
output.flush();

response = (ResponseMessage)input.readObject();

...
}


@Override
protected void onPreExecute() {

try{
// Setup networking
**socket = new Socket(ConstantsRooms.SERVER_ADDRESS, ConstantsRooms.PORT_PUBLIC); -->ERROR**
socket.setTcpNoDelay(true);
output = new ObjectOutputStream(socket.getOutputStream());
output.flush();
input = new ObjectInputStream(socket.getInputStream());

}catch (Exception exp){
Log.e(TAG, "Excepcion socket ---");
exp.printStackTrace();
}
}
}

}


.

stackoverflow.comm

[android help] Convert string to ASCII value in java

android - Convert string to ASCII value in java - Stack Overflow








Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















I have


String name = "admin";


then i do


String char = name.substring(0,1); //char="a"


I want to convert the char to it's ASCII value (97), how can i do this in java?


























Instead of this:



String char = name.substring(0,1); //char="a"


You should use the charAt() method.



char c = name.charAt(0); // c='a'
int ascii = (int)c;






















Very simple. Just cast your char as an int.



char character = 'a';
int ascii = (int) character;


In your case, you need to get the specific Character from the String first and then cast it. Though cast is not required explicitly, but its improves readability.



int ascii = character; // Even this will do the trick.
























Just cast the char to an int.



char character = 'a';
int number = (int) character;


The value of number will be 97.






















It's simple, get the character you want, and convert it to int.



String name = "admin";
int ascii = name.charAt(0);
























Convert the char to int.



String name = "admin";
int ascii = name.toCharArray()[0];


Also :



int ascii = name.charAt(0);





















If you wanted to convert the entire string into concatenated ASCII values then you can use this -



String str = "abc"; // or anything else

StringBuilder sb = new StringBuilder();
for (char c : str.toCharArray())
sb.append((int)c);

BigInteger mInt = new BigInteger(sb.toString());
System.out.println(mInt);


wherein you will get 979899 as output.


Credit to this.


I just copied it here so that it would be convenient for others.






















just a different approach



String s = "admin";
byte[] bytes = s.getBytes("US-ASCII");


bytes[0] will represent ascii of a.. and thus the other characters in the whole array.




















lang-java







.

stackoverflow.comm

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...