应用程序在首次启动后停止,但没有错误

时间:2017-03-28 13:40:39

标签: java android android-studio logcat

您好,非常感谢您根据我的问题投入的时间。

我正在尝试在android studio中运行一个应用程序并且它构建正常,有0个错误,设备上显示应用程序图标(我在不同设备和模拟器上尝试了btw)但是当它启动时,它会在几秒钟后崩溃,说"我的应用"已停止。我试图查看logcat错误,我不明白这个问题。

这是logcat错误文件,请告诉我您是否需要有关此问题的任何其他信息。

    03-28 19:20:23.382 13915-13921/? E/jdwp: Failed sending reply to debugger: Broken pipe
03-28 19:20:23.532 13915-13929/? E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.internal.zzadf.zzg
03-28 19:20:23.762 13915-13915/? E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
03-28 19:20:23.782 13915-13915/? E/OneSignal: OneSignal AppId format is invalid.
                                              Example: 'b2f7f966-d8cc-11e4-bed1-df8f05be55ba'

                                              java.lang.NumberFormatException: Invalid long: "xxxxxxxx"
                                                  at java.lang.Long.invalidLong(Long.java:125)
                                                  at java.lang.Long.parse(Long.java:362)
                                                  at java.lang.Long.parseLong(Long.java:353)
                                                  at java.util.UUID.fromString(UUID.java:201)
                                                  at com.onesignal.OSUtils.initializationChecker(OSUtils.java:52)
                                                  at com.onesignal.OneSignal.init(OneSignal.java:238)
                                                  at com.onesignal.OneSignal.init(OneSignal.java:215)
                                                  at com.onesignal.OneSignal.access$000(OneSignal.java:68)
                                                  at com.onesignal.OneSignal$Builder.init(OneSignal.java:142)
                                                  at com.mp3player.searchonline.MainActivity.onCreate(MainActivity.java:65)
                                                  at android.app.Activity.performCreate(Activity.java:5326)
                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2218)
                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2309)
                                                  at android.app.ActivityThread.access$700(ActivityThread.java:157)
                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
                                                  at android.os.Handler.dispatchMessage(Handler.java:99)
                                                  at android.os.Looper.loop(Looper.java:176)
                                                  at android.app.ActivityThread.main(ActivityThread.java:5317)
                                                  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:1102)
                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
                                                  at dalvik.system.NativeStart.main(Native Method)
03-28 19:20:27.816 13915-13915/com.usmans.songscloud E/AndroidRuntime: FATAL EXCEPTION: main
                                                                       java.lang.NoClassDefFoundError: android.support.v7.internal.widget.TintManager
                                                                           at android.support.design.widget.TabLayout$TabView.<init>(TabLayout.java:1041)
                                                                           at android.support.design.widget.TabLayout.createTabView(TabLayout.java:582)
                                                                           at android.support.design.widget.TabLayout.addTabView(TabLayout.java:616)
                                                                           at android.support.design.widget.TabLayout.addTab(TabLayout.java:334)
                                                                           at android.support.design.widget.TabLayout.addTab(TabLayout.java:309)
                                                                           at android.support.design.widget.TabLayout.setTabsFromPagerAdapter(TabLayout.java:571)
                                                                           at android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:550)
                                                                           at com.mp3player.searchonline.MainActivity.setView(MainActivity.java:93)
                                                                           at com.mp3player.searchonline.MainActivity.onCreate(MainActivity.java:86)
                                                                           at android.app.Activity.performCreate(Activity.java:5326)
                                                                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2218)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2309)
                                                                           at android.app.ActivityThread.access$700(ActivityThread.java:157)
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                           at android.os.Looper.loop(Looper.java:176)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5317)
                                                                           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:1102)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
                                                                           at dalvik.system.NativeStart.main(Native Method)

清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mp3player.searchonline" >

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="21" />

    <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="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.WAKE_LOCK"/>

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/MyMaterialTheme"
        android:name="com.mp3player.searchonline.App" >
        <!--This meta-data tag is required to use Google Play Services.-->
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
        <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
        <activity
            android:name="com.mp3player.searchonline.MainActivity"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustNothing" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.mp3player.searchonline.PlayerActivity"
            android:label="@string/app_name"
            android:theme="@style/MyDialogTheme" >
            </activity>
    </application>

</manifest>

MainActivity.java

package com.mp3player.searchonline;
/**
 * Created by Usman Jamil on 02/02/2017.
 * Usmans.net
 * Skype usman.jamil78
 * email usmanjamil547@gmail.com
 */
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.CursorAdapter;
import android.support.v4.widget.SimpleCursorAdapter;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.support.design.widget.Snackbar;
import com.onesignal.OneSignal;
import java.util.ArrayList;
import java.util.List;

import android.support.design.widget.CoordinatorLayout;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;

public class MainActivity extends AppCompatActivity implements constants  {

    private Toolbar toolbar;
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private CoordinatorLayout coordinatorLayout;
    private SearchView mSearchView;
    private MenuItem searchMenuItem;
    String[] Final_Suggestions=null;
    private SimpleCursorAdapter mAdapter;
        String SearchText=null;
    SongFragment fragment;
    ProgressDialog pDialog;
    String TabFragmentB;
    Boolean Is = false;
    FloatingActionButton Sharebutton;
    String urs;
    SharedPreferences sharedpreferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        coordinatorLayout = (CoordinatorLayout) findViewById(R.id
                .coordinatorLayout);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        viewPager = (ViewPager) findViewById(R.id.viewpager);
        int id = viewPager.getCurrentItem();
        OneSignal.startInit(this).init();

        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
         Sharebutton = (FloatingActionButton) findViewById(R.id.fav);
        Sharebutton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            onshare();
            }
        });

        final String[] from = new String[] {"cityName"};
        final int[] to = new int[] {android.R.id.text1};
        mAdapter = new SimpleCursorAdapter(this,
                android.R.layout.simple_list_item_1,
                null,
                from,
                to,
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    Snackbar snackbar = Snackbar .make(coordinatorLayout, getString(R.string.WelcomeMsg), Snackbar.LENGTH_LONG);
    SongFragment toy1 = (SongFragment) getSupportFragmentManager().findFragmentByTag(
                "android:switcher:" + viewPager.getId() + ":" + 0);
        setView();
        snackbar.show();
    }
    public void setView(){
       Sharebutton.setVisibility(View.VISIBLE);
        setupViewPager(viewPager);
        tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(viewPager);
    }

    private void setupViewPager(ViewPager viewPager) {
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
        adapter.addFragment(new SongFragment(), "Search");
            adapter.addFragment(new DownloadFragment(), "Downloaded");
        viewPager.setAdapter(adapter);
    }


    class ViewPagerAdapter extends FragmentPagerAdapter {
        private final List<Fragment> mFragmentList = new ArrayList<>();
        private final List<String> mFragmentTitleList = new ArrayList<>();

        public ViewPagerAdapter(FragmentManager manager) {
            super(manager);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }

        public void addFragment(Fragment fragment, String title) {
            mFragmentList.add(fragment);
            mFragmentTitleList.add(title);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitleList.get(position);
        }
    }
    public Fragment getActiveFragment() {
        if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
            return null;
        }
        String tag = getSupportFragmentManager().getBackStackEntryAt(getSupportFragmentManager().getBackStackEntryCount() - 1).getName();
        return getSupportFragmentManager().findFragmentByTag(tag);


    }
    @Override
    public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent) {
        if ((paramInt == 4) && (paramKeyEvent.getRepeatCount() == 0)) {
          onexit();
        }
        return super.onKeyDown(paramInt, paramKeyEvent);
    }

    public void onexit() {
        AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
        localBuilder.setTitle("Rate Us");
        localBuilder
                .setMessage(getString(R.string.rating)).setNeutralButton("Rate",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(
                                    DialogInterface paramAnonymousDialogInterface,
                                    int paramAnonymousInt) {
                                MainActivity.this.ratee(MainActivity.this
                                        .getApplicationContext()
                                        .getPackageName());
                            }
                        })
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(
                            DialogInterface paramAnonymousDialogInterface,
                            int paramAnonymousInt) {

                        paramAnonymousDialogInterface.dismiss();
                        MainActivity.this.finish();

                    }
                });
        localBuilder.show();
    }
    public void onshare() {
        AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
        localBuilder.setTitle("Share");
        localBuilder
                .setMessage(getString(R.string.share)).setNeutralButton("Share",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(
                            DialogInterface paramAnonymousDialogInterface,
                            int paramAnonymousInt) {
                        MainActivity.this.share(getString(R.string.ShareMsg)+MainActivity.this
                                .getApplicationContext()
                                .getPackageName());
                    }
                })
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(
                            DialogInterface paramAnonymousDialogInterface,
                            int paramAnonymousInt) {
                        paramAnonymousDialogInterface.dismiss();
                    }
                });
        localBuilder.show();
    }

    public void ratee(String paramString) {
        try {
            Intent localIntent = new Intent("android.intent.action.VIEW");
            localIntent
                    .setData(Uri.parse("market://details?id=" + paramString));
            startActivity(localIntent);
            return;
        } catch (Exception localException) {

        }
    }
    public void share(String paramString) {
    try {
            Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT,paramString);
        sendIntent.setType("text/plain");
        startActivity(sendIntent);
            return;
        } catch (Exception localException) {

        }

    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

 }

的build.gradle

apply plugin: 'com.android.application'
 android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'

    defaultConfig {
        applicationId "com.usmans.songscloud"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        manifestPlaceholders = [onesignal_app_id: "xxxxxxxx-e269-4dfb-8b48-357b707acdae",
                                // Project number pulled from dashboard, local value is ignored.
                                onesignal_google_project_number: "108880509xxxx"]
        useLibrary 'org.apache.http.legacy'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    maven {
        url 'https://dl.bintray.com/ayz4sci/maven/'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.cjj.materialrefeshlayout:library:1.3.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.ayz4sci.androidfactory:downloadprogress:1.0.1'
    compile 'com.android.support:support-v4:25.0.0'
    // Required for OneSignal, even if you have added FCM.
    compile 'com.google.android.gms:play-services-gcm:+'
    // Required for geotagging
    compile 'com.google.android.gms:play-services-location:+'
    compile 'com.google.android.gms:play-services-analytics:+'
    // play-services-analytics is only needed when using 8.1.0 or older.
    // compile 'com.google.android.gms:play-services-analytics:+'
    compile 'com.google.android.gms:play-services-ads:10.2.1'
    compile 'com.onesignal:OneSignal:3.4.3'
}

1 个答案:

答案 0 :(得分:0)

似乎你传递给OneSignal框架的“app id”应该是Long类型,但是你传递的是无效值。

请参阅此错误讨论:OneSignal AppId format is invalid