我正在处理位置基础警报。我正在尝试在用户输入位置时给出一些通知。但是一旦我选择我当前的位置以查看我的应用程序是否给出了一些通知它只是崩溃。我想要显示通知。 救命啊!
Logcat文件
10-01 23:23:23.608: D/dalvikvm(16166): GC_CONCURRENT freed 3395K, 32% free 10967K/16084K, paused 35ms+22ms, total 233ms
10-01 23:23:31.355: D/dalvikvm(16166): GC_CONCURRENT freed 772K, 33% free 10880K/16076K, paused 181ms+7ms, total 480ms
10-01 23:23:34.508: D/HAWAII_EGL(16166): eglMakeCurrent(NULL) Thread: 16217
10-01 23:23:34.508: D/HAWAII_EGL(16166): eglDestroySurface() surface: 0x40027fc8, android window 0x40027818, Thread: 16217
10-01 23:23:34.879: D/dalvikvm(16166): newInstance failed: p0 i0 [0 a1
10-01 23:23:34.889: D/AndroidRuntime(16166): Shutting down VM
10-01 23:23:34.889: W/dalvikvm(16166): threadid=1: thread exiting with uncaught exception (group=0x40e3c930)
10-01 23:23:34.909: E/AndroidRuntime(16166): FATAL EXCEPTION: main
10-01 23:23:34.909: E/AndroidRuntime(16166): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.haider.trymap/com.haider.trymap.ProximityActivity}: java.lang.InstantiationException: can't instantiate class com.haider.trymap.ProximityActivity
10-01 23:23:34.909: E/AndroidRuntime(16166): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
10-01 23:23:34.909: E/AndroidRuntime(16166): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2309)
10-01 23:23:34.909: E/AndroidRuntime(16166): at android.app.ActivityThread.access$700(ActivityThread.java:157)
10-01 23:23:34.909: E/AndroidRuntime(16166): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
10-01 23:23:34.909: E/AndroidRuntime(16166): at android.os.Handler.dispatchMessage(Handler.java:99)
10-01 23:23:34.909: E/AndroidRuntime(16166): at android.os.Looper.loop(Looper.java:176)
10-01 23:23:34.909: E/AndroidRuntime(16166): at android.app.ActivityThread.main(ActivityThread.java:5317)
10-01 23:23:34.909: E/AndroidRuntime(16166): at java.lang.reflect.Method.invokeNative(Native Method)
10-01 23:23:34.909: E/AndroidRuntime(16166): at java.lang.reflect.Method.invoke(Method.java:511)
10-01 23:23:34.909: E/AndroidRuntime(16166): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
10-01 23:23:34.909: E/AndroidRuntime(16166): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
10-01 23:23:34.909: E/AndroidRuntime(16166): at dalvik.system.NativeStart.main(Native Method)
10-01 23:23:34.909: E/AndroidRuntime(16166): Caused by: java.lang.InstantiationException: can't instantiate class com.haider.trymap.ProximityActivity
10-01 23:23:34.909: E/AndroidRuntime(16166): at java.lang.Class.newInstanceImpl(Native Method)
10-01 23:23:34.909: E/AndroidRuntime(16166): at java.lang.Class.newInstance(Class.java:1319)
10-01 23:23:34.909: E/AndroidRuntime(16166): at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
10-01 23:23:34.909: E/AndroidRuntime(16166): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2171)
10-01 23:23:34.909: E/AndroidRuntime(16166): ... 11 more
ProximityActivity.java
public abstract class ProximityActivity extends Activity {
String notificationTitle;
String notificationContent;
String tickerMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
boolean proximity_entering = getIntent().getBooleanExtra(LocationManager.KEY_PROXIMITY_ENTERING, true);
if(proximity_entering){
Toast.makeText(getBaseContext(),"Entering the region" ,Toast.LENGTH_LONG).show();
notificationTitle="Proximity - Entry";
notificationContent="Entered the region";
tickerMessage = "Entered the region";
}else{
Toast.makeText(getBaseContext(),"Exiting the region" ,Toast.LENGTH_LONG).show();
notificationTitle="Proximity - Exit";
notificationContent="Exited the region";
tickerMessage = "Exited the region";
}
Intent notificationIntent = new Intent(getApplicationContext(),NotificationView.class);
notificationIntent.putExtra("content", notificationContent );
/** This is needed to make this intent different from its previous intents */
notificationIntent.setData(Uri.parse("tel:/"+ (int)System.currentTimeMillis()));
/** Creating different tasks for each notification. See the flag Intent.FLAG_ACTIVITY_NEW_TASK */
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
/** Getting the System service NotificationManager */
NotificationManager nManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
/** Configuring notification builder to create a notification */
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
.setWhen(System.currentTimeMillis())
.setContentText(notificationContent)
.setContentTitle(notificationTitle)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setTicker(tickerMessage)
.setContentIntent(pendingIntent);
/** Creating a notification from the notification builder */
Notification notification = notificationBuilder.build();
/** Sending the notification to system.
* The first argument ensures that each notification is having a unique id
* If two notifications share same notification id, then the last notification replaces the first notification
* */
nManager.notify((int)System.currentTimeMillis(), notification);
/** Finishes the execution of this activity */
finish();
}
}
清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.haider.trymap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="21" />
<uses-permission android:name="com.haider.trymap.permission.MAPS_RECEIVE" />
<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" />
<permission
android:name="com.haider.trymap.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"
/>
<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="AIzaSyBbazKulELXN4QPDM696ix2ENAZAoLHSYY" />
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ProximityActivity"
android:label="@string/app_name" >
<intent-filter >
<action android:name="com.haider.activity.proximity"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".NotificationView"
android:label="@string/app_name" >
<intent-filter >
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:0)
您无法实例化抽象类。使ProximityActivity
具体或建立一个扩展它的具体类。