Android Studio App does not open (Mapbox) - android-studio

I want to build an app with mapbox where a map is displayed. I used this video: https://www.youtube.com/watch?v=sTlOaFm6ttU&lc=UgzYC-Y-6pEmrsmmvTl4AaABAg.9F9Fdptkxka9FDwq0btJOL
There are many videos that simply show the same code but it never works. When running the code it says that there is no error and the app on the virtual device opens. But after a second of blank screen it closes immediatly.
Main Activity:
package com.example.mapboxedtmdev;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.maps.MapView;
public class MainActivity extends AppCompatActivity {
private MapView mapView;
#Override
protected void onStart() {
super.onStart();
mapView.onStart();
}
#Override
protected void onStop() {
super.onStop();
mapView.onStop();
}
#Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
#Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
#Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this, "pk.eyJ1Ijoia2VycnlraWxpYW4iLCJhIjoiY2tna3QzMzZnMG1naTMwbmE4ejF0dnFuZiJ9.BXqcjQ4giUcsL1VDzTqPSQ");
setContentView(R.layout.activity_main);
mapView=(MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.setStyleUrl(Style.MAPBOX_STREETS);
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.mapbox.mapboxsdk.maps.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:mapbox_cameraTargetLat="16"
app:mapbox_cameraTargetLng="108"
app:mapbox_cameraZoom="11"/>
</RelativeLayout>
In Android Manifest I added the permissions:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapboxedtmdev">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
In Build.gradle(Module) I added this under dependencies:
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.2#aar')
{
transitive=true
}
In Build.gradle(Project) I added the mavenCentral():
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The Logcat just shows this in red:
2020-10-26 11:29:52.571 9436-9436/com.example.mapboxedtmdev E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mapboxedtmdev, PID: 9436
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapboxedtmdev/com.example.mapboxedtmdev.MainActivity}: java.lang.SecurityException: getDataNetworkTypeForSubscriber
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.SecurityException: getDataNetworkTypeForSubscriber
at android.os.Parcel.createExceptionOrNull(Parcel.java:2373)
at android.os.Parcel.createException(Parcel.java:2357)
at android.os.Parcel.readException(Parcel.java:2340)
at android.os.Parcel.readException(Parcel.java:2282)
at com.android.internal.telephony.ITelephony$Stub$Proxy.getNetworkTypeForSubscriber(ITelephony.java:8762)
at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:3021)
at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:2985)
at com.mapbox.services.android.telemetry.utils.TelemetryUtils.getCellularNetworkType(TelemetryUtils.java:102)
at com.mapbox.services.android.telemetry.MapboxTelemetry.pushEvent(MapboxTelemetry.java:482)
at com.mapbox.mapboxsdk.maps.MapView.onCreate(MapView.java:207)
at com.example.mapboxedtmdev.MainActivity.onCreate(MainActivity.java:56)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:223) 
at android.app.ActivityThread.main(ActivityThread.java:7656) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
2020-10-26 11:29:52.611 9436-9436/com.example.mapboxedtmdev I/Process: Sending signal. PID: 9436 SIG: 9
I hope anyone can help me because it seems that the app works on every other pc but not at my pc.

I found a solution: Take another device. At first, I had a virtual device (Google Pixel 2) but now I took my own smartphone as device.

add implementation "implementation com.mapbox.mapboxsdk:mapbox-android-telemetry:6.1.0"
to dependencies block in build.gradle
this issue is about new policy of android, and will fix later.

Related

Android InflateException in unknown class when creating alert from XML file

I have changed the app theme from Theme.appcompat to Theme.MaterialComponents
error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rohindh.kcthappytummy, PID: 16582
android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating
class <unknown>
Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter.createpopup(AddedtRecyclerAdapter.java:70)
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter.access$000(AddedtRecyclerAdapter.java:26)
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter$1.onClick(AddedtRecyclerAdapter.java:62)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme
to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
at
com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:217)
at
com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:145)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:458)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:417)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
at android.view.LayoutInflater.createView(LayoutInflater.java:647) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter.createpopup(AddedtRecyclerAdapter.java:70) 
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter.access$000(AddedtRecyclerAdapter.java:26) 
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter$1.onClick(AddedtRecyclerAdapter.java:62) 
at android.view.View.performClick(View.java:6597) 
at android.view.View.performClickInternal(View.java:6574) 
at android.view.View.access$3100(View.java:778) 
at android.view.View$PerformClick.run(View.java:25885) 
at android.os.Handler.handleCallback(Handler.java:873) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
When user clicks the edit button, an Alert dialog window should appear but I don't know what I'm missing
Adapter code
public class AddedtRecyclerAdapter extends RecyclerView.Adapter<AddedtRecyclerAdapter.ViewHolder> {
private Context context;
private ArrayList<Dishmodel> dishmodellist;
//pop elements and requirement
private AlertDialog.Builder build;
private AlertDialog dialog;
private EditText nameedt,desedt,pricedt;
private ImageButton closebtn;
private Button addbtn;
private ProgressBar progressBar;
public AddedtRecyclerAdapter(Context context, ArrayList<Dishmodel> dishmodellist) {
this.context = context;
this.dishmodellist = dishmodellist;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.dish_list_item,parent,false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
#Override
public void onBindViewHolder(#NonNull AddedtRecyclerAdapter.ViewHolder holder, final int position) {
final Dishmodel dish= dishmodellist.get(position);
holder.name.setText(dish.getName());
holder.price.setText(String.valueOf(dish.getPrice()));
holder.descirption.setText(dish.getDescription());
//edit btn clicked then create a pop window and send the current array with is position
holder.edtbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
createpopup(dish,position);
}
});
}
private void createpopup(Dishmodel dish, int position) {
build = new AlertDialog.Builder(context);
View view = LayoutInflater.from(context).inflate(R.layout.popup,null);
nameedt = view.findViewById(R.id.itemname);
desedt = view.findViewById(R.id.itemdes);
pricedt = view.findViewById(R.id.itemprice);
addbtn = view.findViewById(R.id.itemaddbtn);
closebtn = view.findViewById(R.id.closebtn);
progressBar = view.findViewById(R.id.addprogress);
build.setView(view);
dialog = build.create();
dialog.show();
}
#Override
public int getItemCount() {
return dishmodellist.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView name,descirption,price;
ImageButton edtbtn,deletebtn;
public ViewHolder(#NonNull View itemView) {
super(itemView);
name = itemView.findViewById(R.id.dishname);
descirption = itemView.findViewById(R.id.dishdes);
price = itemView.findViewById(R.id.dishprice);
edtbtn = itemView.findViewById(R.id.editbtn);
deletebtn = itemView.findViewById(R.id.deletebtn);}
}
error in 26 line in xml ie material.TextInputLayout
xml 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="380dp" android:paddingHorizontal="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/closeicon"
android:id="#+id/closebtn"
android:layout_alignParentEnd="true"
android:backgroundTint="#color/appcolor"
/>
<ProgressBar
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/addprogress"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/outlinedTextField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Item Name"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/itemname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto"
android:maxLines="1"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/outlinedTextField1"
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:hint="Item Description"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/itemdes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:fontFamily="#font/roboto"
android:inputType="textMultiLine" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/outlinedTextField2"
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:hint="Item Price"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/itemprice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:fontFamily="#font/roboto"
android:inputType="number" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:backgroundTint="#color/appcolor"
android:layout_marginTop="25dp"
android:id="#+id/itemaddbtn"
android:text="Add"/>
</LinearLayout>
Manifest code
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
Style
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowDisablePreview">false</item>
</style>
<style name="myDialog" parent="Theme.MaterialComponents.DayNight.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
dependencies
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-database:19.2.1'
implementation 'com.google.firebase:firebase-auth:19.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'}
I have referred to many solutions in stackoverflow but can't able to solve this issue. If anyone knows solution for this issue please help out with this.
Thanks in advance

Application stops but there is no error

Here is the new logcat of the error, I do not understand what it is about I can't seem to figure out this error
11-25 15:56:18.773 6776-6776/com.example.ghost.prochat E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ghost.prochat/com.example.ghost.prochat.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2204)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2254)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5069)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.ghost.prochat.MainActivity.onCreate(MainActivity.java:56)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1092)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2254) 
at android.app.ActivityThread.access$600(ActivityThread.java:141) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5069) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.ghost.prochat.MainActivity.onCreate(MainActivity.java:56) 
at android.app.Activity.performCreate(Activity.java:5104) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1092) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2254) 
at android.app.ActivityThread.access$600(ActivityThread.java:141) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5069) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
at android.view.View.(View.java:3340)
at android.view.ViewGroup.(ViewGroup.java:431)
at android.widget.LinearLayout.(LinearLayout.java:176)
at android.widget.LinearLayout.(LinearLayout.java:172)
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
at android.view.LayoutInflater.createView(LayoutInflater.java:587) 
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.ghost.prochat.MainActivity.onCreate(MainActivity.java:56) 
at android.app.Activity.performCreate(Activity.java:5104) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1092) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2254) 
at android.app.ActivityThread.access$600(ActivityThread.java:141) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5069) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
at dalvik.system.NativeStart.main(Native Method) 
my mainActivity is as follows
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
//defining view objects
private EditText editTextEmail;
private EditText displayUsername;
private EditText editTextPassword;
private Button buttonSignup;
private TextView textViewSignin;
private ProgressDialog progressDialog;
//defining firebaseauth object
private FirebaseAuth firebaseAuth;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initializing firebase auth object
firebaseAuth = FirebaseAuth.getInstance();
//if getCurrentUser does not returns null
if (firebaseAuth.getCurrentUser() != null) {
//that means user is already logged in
//so close this activity
finish();
//and open profile activity
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
}
//initializing views
editTextEmail = (EditText) findViewById(R.id.editTextEmail);
displayUsername = (EditText) findViewById(R.id.displayUsername);
editTextPassword = (EditText) findViewById(R.id.editTextPassword);
textViewSignin = (TextView) findViewById(R.id.textViewSignin);
buttonSignup = (Button) findViewById(R.id.buttonSignup);
progressDialog = new ProgressDialog(this);
//attaching listener to button
buttonSignup.setOnClickListener(this);
textViewSignin.setOnClickListener(this);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
private void registerUser() {
//getting email and password from edit texts
String email = editTextEmail.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
//checking if email and passwords are empty
if (TextUtils.isEmpty(email)) {
Toast.makeText(this, "Please enter email", Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(this, "Please enter password", Toast.LENGTH_LONG).show();
return;
}
//if the email and password are not empty
//displaying a progress dialog
progressDialog.setMessage("Registering Please Wait...");
progressDialog.show();
//creating a new user
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
//checking if success
if (task.isSuccessful()) {
finish();
final FirebaseUser user = task.getResult().getUser();
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName(String.valueOf(displayUsername))
.setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.png"))
.build();
user.updateProfile(profileUpdates);
FirebaseDatabase.getInstance().getReference("users").child(user.getUid()).setValue(UserList.user);
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
} else {
//display some message here
Toast.makeText(MainActivity.this, "Registration Error", Toast.LENGTH_LONG).show();
}
progressDialog.dismiss();
}
});
}
#Override
public void onClick(View view) {
if (view == buttonSignup) {
registerUser();
}
if (view == textViewSignin) {
//open login activity when user taps on the already registered textview
startActivity(new Intent(this, LoginActivity.class));
}
}
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
public Action getIndexApiAction() {
Thing object = new Thing.Builder()
.setName("Main Page") // TODO: Define a title for the content shown.
// TODO: Make sure this auto-generated URL is correct.
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
.build();
return new Action.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}
#Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
AppIndex.AppIndexApi.start(client, getIndexApiAction());
}
#Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
AppIndex.AppIndexApi.end(client, getIndexApiAction());
client.disconnect();
}
}
my main.activity is here, i cant see any errors
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/head"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.ghost.prochat.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="User Registration"
android:id="#+id/textView"
android:layout_gravity="center_horizontal" />
<EditText
android:id="#+id/displayUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:hint="Username"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/editTextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:hint="Enter email"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:hint="Enter password"
android:inputType="textPassword" />
<Button
android:id="#+id/buttonSignup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Signup" />
<TextView
android:text="Already Registered? Signin Here"
android:id="#+id/textViewSignin"
android:textAlignment="center"
android:layout_margin="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Your crash is caused by the following:
Caused by: java.lang.UnsupportedOperationException: Can't convert to
dimension: type=0x1 at
android.content.res.TypedArray.getDimensionPixelSize
So the problem is in one of your dimensions:
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
I can guess, that you used wrong dimension type, e.g. sp instead of dp
Here is how a right dimension should look:
<dimen name="activity_vertical_margin">36dp</dimen>
Also please ensure your dimension is defined in an xml in the valuesfolder as it mentioned in this answer

Why can't i see logs of code pieces triggered by AlarmManager?

I'm very new to android studio development so the answer is probably trivial.
That being said, I've busted my head around the problem for a day now :/
I am trying to run a chunk of code every 10 seconds even when the app is closed using AlarmManager.
I copy-pasted what is suggested in this guide https://guides.codepath.com/android/Starting-Background-Services
I'm a little puzzled by the result -
I think I do get alarm triggered every 10 seconds, as indicated in the log:
04-20 21:25:44.125 557-632/? D/AlarmManager: Triggered Alarm 22ad4130
RTC_WAKEUP IntentSender{220fb650: PendingIntentRecord{2243b570
com.example.somelocation.myapplication broadcastIntent}} 04-20
21:25:44.125 557-557/? V/AlarmManager: triggered: flg=0x14
cmp=com.example.somelocation.myapplication/.MyAlarmReceiver
But i can't see any of my custom logs positioned inside my BroadcastReceiver or my IntentService.
MyTestService:
package com.example.somelocation.myapplication;
import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
public class MyTestService extends IntentService {
public MyTestService() {
super("MyTestService");
}
#Override
protected void onHandleIntent(Intent intent) {
// Do the task here
Log.i("MyTestService", "Service running"); // Can't see this log
}
}
MyAlarmReceiver:
package com.example.somelocation.myapplication;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class MyAlarmReceiver extends BroadcastReceiver {
public static final int REQUEST_CODE = 12345;
#Override
public void onReceive(Context context, Intent intent) {
Log.e("MyTestService","broadcastreciever onReceive called"); // Can't see this log
Intent i = new Intent(context, MyTestService.class);
i.putExtra("foo", "bar");
context.startService(i);
}
}
Main Activity:
package com.example.somelocation.myapplication;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView batteryInfo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scheduleAlarm();
}
public void scheduleAlarm() {
Intent intent = new Intent(getApplicationContext(), MyAlarmReceiver.class);
final PendingIntent pIntent = PendingIntent.getBroadcast(this, MyAlarmReceiver.REQUEST_CODE,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
long firstMillis = System.currentTimeMillis();
AlarmManager alarm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, firstMillis,
10000, pIntent);
}
}
my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.somelocation.myapplication">
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<receiver
android:name=".MyAlarmReceiver"
android:process=":remote" >
</receiver>
<service
android:name=".MyTestService"
android:exported="false"/>
</activity>
</application>
</manifest>
What am I missing?
update:
Got it! It was an error in my manifest file:
The close tag of the main activity was after the receiver declaration. should be:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".MyAlarmReceiver"
android:process=":remote" >
</receiver>
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:exported="true"/>
</application>
The log is being printed on the console... here is the log I am getting
04-22 18:30:28.421 1830-4146/com.example.somelocation.myapplication I/MyTestService: Service running
04-22 18:30:45.337 2641-2641/com.example.somelocation.myapplication:remote E/MyTestService: broadcastreciever onReceive called
04-22 18:30:45.344 1830-4394/com.example.somelocation.myapplication I/MyTestService: Service running
04-22 18:30:48.4032641-2641/com.example.somelocation.myapplication:remote E/MyTestService: broadcastreciever onReceive called
You are creating a separate process('remote') for the BroadcastReceiver and your logcat may be setup to display only the main process create at first.
See the screenshots -
So change the application process from the dropdown and also select the log level to Verbose.

Android studio 1.0.1 google map v2 not working on API 10

I create new project and select minimum sdk 2.3.3 gingerbread then select Google map Activity . android studio default preparations do . this project work on api 11 and above و but in api 10(for example Galaxy Y s5360, not install google play services) message show "get google play services" . For example, I have some applications that run in this version and this device(s5360) google map work without any problem .
please help ( sorry for my english)
my build.gradle is :
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.ehm.tantum"
minSdkVersion 10
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.android.support:support-v4:21.0.3' }
My mainfest is :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ehm.tantum" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_maps_key" /> // i have API key this prject
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
my mapActivity :
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
}
#Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
My libs folder default is empty .
please help .
If you have not installed google play services on your device, maps will never work.
You need the same version you use for compiling the app (6.5.87 according to your buildfile)
The fact that other apps are working, means (or i suppose at least) that is because you have an outdated version of play services and the other apps are compiled with older version of play services.
Try to update services on your device

i want to implement searchbar concept in my app

i want to implement searcb bar concept in my app .
when ever user clicks on searbar the keyboard buttons need to display with default searchable button in it ..i followed few of the links ...but unable to get the searchable bar nor the keyboard populated buttons ...
please help me thanks in advance .
this is my searchable.xml placed res/xml
<searchable
android:label="#string/app_label"
android:hint="#string/search_hint" >
</searchable>
and this is my manifest file
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".SearchboxActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
</application>
here is the activity ...
package com.hands;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
public class SearchboxActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get the intent, verify the action and get the query
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
// doMySearch(query);
}
}
private void doMySearch(String query) {
// TODO Auto-generated method stub
System.out.println("hello 2");
}
}

Resources