Monday, November 11, 2013

android.view.WindowManager$BadTokenException: Unable to add window, is your activity running? [android help]


android.view.WindowManager$BadTokenException: Unable to add window, is your activity running?



i have a popup windows on my activity, my popup was working fine, untill i click on spinner it gives me an error as logcat said :



11-01 15:28:31.131: E/AndroidRuntime(10846): android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@41f56ec8 is not valid; is your activity running?
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.view.ViewRootImpl.setView(ViewRootImpl.java:692)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:345)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.view.Window$LocalWindowManager.addView(Window.java:556)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.widget.PopupWindow.invokePopup(PopupWindow.java:1013)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:922)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.widget.ListPopupWindow.show(ListPopupWindow.java:595)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.widget.Spinner$DropdownPopup.show(Spinner.java:983)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.widget.Spinner.performClick(Spinner.java:608)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.view.View$PerformClick.run(View.java:17337)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.os.Handler.handleCallback(Handler.java:615)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.os.Handler.dispatchMessage(Handler.java:92)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.os.Looper.loop(Looper.java:137)
11-01 15:28:31.131: E/AndroidRuntime(10846): at android.app.ActivityThread.main(ActivityThread.java:4895)
11-01 15:28:31.131: E/AndroidRuntime(10846): at java.lang.reflect.Method.invokeNative(Native Method)
11-01 15:28:31.131: E/AndroidRuntime(10846): at java.lang.reflect.Method.invoke(Method.java:511)
11-01 15:28:31.131: E/AndroidRuntime(10846): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
11-01 15:28:31.131: E/AndroidRuntime(10846): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
11-01 15:28:31.131: E/AndroidRuntime(10846): at dalvik.system.NativeStart.main(Native Method)


this is my code:



imgSearch.setOnClickListener(new OnClickListener(){
public void onClick(View v) {

// Intent cari= new Intent(MerchantSimasCard.this,Pencarian.class);
// startActivity(cari);
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View popupSet = inflater.inflate(R.layout.cari, null);
spin_all=(Spinner)popupSet.findViewById(R.id.spin_kategori);
spin_kota=(Spinner)popupSet.findViewById(R.id.spin_kota);
spin_abjad=(Spinner)popupSet.findViewById(R.id.spin_abjad);

search=(EditText)popupSet.findViewById(R.id.search);
buttonsearch=(Button)popupSet.findViewById(R.id.buttonsearch);

final PopupWindow pw = new PopupWindow(popupSet, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

new SpinnerKategori().execute();
buttonsearch.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

if (ListMerchant.size()>0) {
ListMerchant.clear();
ListChildMerchantChild.clear();
}
String url1 = null;
try {
url1 = "http://www3.abc.co.id/";
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
pw.dismiss();
System.out.println(url1);
new TerbaruAsyncTask(url1).execute();
}

});
pw.showAtLocation(findViewById(R.id.merchantsimascard), Gravity.CENTER, 0, 0);
}

});
public class SpinnerKategori extends AsyncTask{
String url ="http://www3.sinarmasmsiglife.co.id/E-Policy/ios/sc_merchant.htm?s=1";

public SpinnerKategori(){
this.url=url;
}

@Override
protected void onPreExecute(){
super.onPreExecute();
dialog=ProgressDialog.show(MerchantSimasCard.this,"", "melakukan pengambilan data");
}

@Override
protected String doInBackground(Void... params) {
String result="";
try {
result=Connection.get(url);
}catch (Exception e){
result="";
}
return result;
}

@Override
protected void onPostExecute(String result){
super.onPostExecute(result);

ParsingCategory(result.replace("\n", "").trim());
ArrayAdapter spinnerMenu = new ArrayAdapter(MerchantSimasCard.this,R.layout.spinner_style, kategori);
spinnerMenu.setDropDownViewResource(R.layout.spinner_dropdown);
spin_all.setAdapter(spinnerMenu);

ArrayAdapter SpinnerKota = new ArrayAdapter(MerchantSimasCard.this, R.layout.spinner_style, kota);
SpinnerKota.setDropDownViewResource(R.layout.spinner_dropdown);
spin_kota.setAdapter(SpinnerKota);


ArrayAdapter Spinnerabjad= new ArrayAdapter(MerchantSimasCard.this,R.layout.spinner_style, abjad);
Spinnerabjad.setDropDownViewResource(R.layout.spinner_dropdown);
spin_abjad.setAdapter(Spinnerabjad);
dialog.dismiss();

}
}

private void ParsingCategory(String result) {
if (!result.equals("")) {
try {
JSONObject jsonObject = new JSONObject(result);

JSONArray cat = jsonObject.getJSONArray("cat");

for (int i=0; i
JSONObject status = cat.getJSONObject(i);
String Category=status.getString("name");

kategori.add(Category);

}
JSONArray city=jsonObject.getJSONArray("cit");
for (int j=0; j
String kot = (String) city.get(j);
kota.add(kot);

}
}

catch (Exception e) {
Log.d("TEST CHART", e.getMessage());
}
}

}


i have no idea to find my false, i hope there is someone can help me to solve my problem. thank you



Read more

stackoverflow.comm



Android Studio gradle refresh destroys project [android help]


Android Studio gradle refresh destroys project



I'm having some issues adding dependencies to my build.gradle in Android Studio.


Every time I click on the "Refresh all Gradle Projects" after changing the build.gradle, my project gets wiped: Gradle example


Oddly, the files still exist on disk, but I can no longer build or make any code changes. Restarting Android Studio has no effect.


Am I doing something wrong? Is anybody else experiencing the same issue?


Using the latest Android Studio 0.3.1, a blank project and in-built Gradle wrapper.



Read more

stackoverflow.comm



After Google Play Service update to version 13 I got an error [android help]


After Google Play Service update to version 13 I got an error


java - After Google Play Service update to version 13 I got an error - 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.
















Caused by: java.lang.illegalargumentexception 11-01 11:08:12.845: E/AndroidRuntime(28885): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. You must have the following declaration within the element:


How resolve this error?


google-play-services_lib Manifest




package="com.google.android.gms"
android:versionCode="4030530"
android:versionName="4.0.30 (889083-30)" >






















lang-java






Read more

stackoverflow.comm



Android Studio java.lang.RuntimeException: Unable to start activity ComponentInfo [android help]


Android Studio java.lang.RuntimeException: Unable to start activity ComponentInfo



I'm moving now my project from Android Studio 0.2.x to 0.3.0 and I have quite strange problem.


LoginActivity.java



public class LoginActivity extends Activity implements OnClickListener, TextWatcher {

private EditText _loginEditText;
private EditText _passwordEditText;
private Button _loginButton;

private String _login;
private String _password;
private String _result;

private ProgressDialog _progressDialog;

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

if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}

_loginEditText = (EditText) findViewById(R.id.loginEditText);
_loginEditText.addTextChangedListener(this);

_passwordEditText = (EditText) findViewById(R.id.passwordEditText);
_passwordEditText.addTextChangedListener(this);

_loginEditText.requestFocus();

_loginButton = (Button) findViewById(R.id.loginButton);
_loginButton.setOnClickListener(this);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.activity_login);

_loginEditText = (EditText) findViewById(R.id.loginEditText);
_loginEditText.addTextChangedListener(this);
_loginEditText.setText(_login);
_loginEditText.setSelection(_loginEditText.getText().length());

_passwordEditText = (EditText) findViewById(R.id.passwordEditText);
_passwordEditText.addTextChangedListener(this);
_passwordEditText.setText(_password);
_passwordEditText.setSelection(_passwordEditText.getText().length());

_loginEditText.requestFocus();

_loginButton = (Button) findViewById(R.id.loginButton);
_loginButton.setOnClickListener(this);
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.loginButton: {
//SMTH...
}
}
}

@Override
public void afterTextChanged(Editable s) {
if (_loginEditText.getText().hashCode() == s.hashCode()) {
_loginEditText = (EditText) findViewById(R.id.loginEditText);
_login = _loginEditText.getText().toString().trim();
} else if (_passwordEditText.getText().hashCode() == s.hashCode()) {
_passwordEditText = (EditText) findViewById(R.id.passwordEditText);
_password = _passwordEditText.getText().toString().trim();
}
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login, menu);
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.
switch (item.getItemId()) {
case R.id.action_settings:
return true;
}
return super.onOptionsItemSelected(item);
}

/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {

public PlaceholderFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_login, container, false);
return rootView;
}
}
}


activity_login.xml:



xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LoginActivity"
tools:ignore="MergeRootFrame" />


fragment_login.xml:



xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".LoginActivity$PlaceholderFragment">

android:id="@+id/loginEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="@string/login_edittext_login" />

android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="@string/login_edittext_password" />

android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/login_button_login" />




And my app crashes on lines:



_loginEditText.addTextChangedListener(this);
_passwordEditText.addTextChangedListener(this);
_loginEditText.requestFocus();
_loginButton.setOnClickListener(this);


etc. so it looks like I couldn't access to these elements (loginEditText, passwordEditText, loginButton) from xml files. Before AS 0.3.0 it was only one *.xml file for one Acitivity, but now on 0.3.0 it default generate two *.xml files. I know, that I could overcome this problem, removing one of *.xml file and PlaceholderFragment, but how to solve the problem with two default *.xml files?


Logcat:



java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package.projectname/com.package.projectname.LoginActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.access$600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.package.projectname.LoginActivity.onCreate(LoginActivity.java:51)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.access$600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)


Read more

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...