关于StackExchange的第一个问题所以我希望你能原谅我的错误。
我正在开发一个应用程序,这是一个csipsimple项目分叉。但是每当我尝试使用intent或activity launcher app启动活动时,应用程序都会崩溃。
当我尝试启动活动时,这是堆栈跟踪(除了SplashActivity之外的任何活动都是相同的,这是启动器活动并且运行正常。):
编辑错误(意外删除了清单条目,但问题仍然存在。)
07-21 15:33:18.584: E/AndroidRuntime(5827): FATAL EXCEPTION: main
07-21 15:33:18.584: E/AndroidRuntime(5827): Process: com.myapp.client, PID: 5827
07-21 15:33:18.584: E/AndroidRuntime(5827): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.client/com.myapp.client.LoginActivity}: java.lang.NullPointerException
07-21 15:33:18.584: E/AndroidRuntime(5827): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
07-21 15:33:18.584: E/AndroidRuntime(5827): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
07-21 15:33:18.584: E/AndroidRuntime(5827): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-21 15:33:18.584: E/AndroidRuntime(5827): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-21 15:33:18.584: E/AndroidRuntime(5827): at android.os.Handler.dispatchMessage(Handler.java:102)
07-21 15:33:18.584: E/AndroidRuntime(5827): at android.os.Looper.loop(Looper.java:136)
07-21 15:33:18.584: E/AndroidRuntime(5827): at android.app.ActivityThread.main(ActivityThread.java:5001)
07-21 15:33:18.584: E/AndroidRuntime(5827): at java.lang.reflect.Method.invokeNative(Native Method)
07-21 15:33:18.584: E/AndroidRuntime(5827): at java.lang.reflect.Method.invoke(Method.java:515)
07-21 15:33:18.584: E/AndroidRuntime(5827): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-21 15:33:18.584: E/AndroidRuntime(5827): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-21 15:33:18.584: E/AndroidRuntime(5827): at dalvik.system.NativeStart.main(Native Method)
07-21 15:33:18.584: E/AndroidRuntime(5827): Caused by: java.lang.NullPointerException
07-21 15:33:18.584: E/AndroidRuntime(5827): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
07-21 15:33:18.584: E/AndroidRuntime(5827): at android.app.AlertDialog.<init>(AlertDialog.java:98)
07-21 15:33:18.584: E/AndroidRuntime(5827): at android.app.ProgressDialog.<init>(ProgressDialog.java:77)
07-21 15:33:18.584: E/AndroidRuntime(5827): at com.myapp.client.db.MySQLProvider.<init>(MySQLProvider.java:65)
07-21 15:33:18.584: E/AndroidRuntime(5827): at com.myapp.client.LoginActivity.onCreate(LoginActivity.java:69)
07-21 15:33:18.584: E/AndroidRuntime(5827): at android.app.Activity.performCreate(Activity.java:5231)
07-21 15:33:18.584: E/AndroidRuntime(5827): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-21 15:33:18.584: E/AndroidRuntime(5827): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
07-21 15:33:18.584: E/AndroidRuntime(5827): ... 11 more
以下代码是我的SplashActivity.java,它调用了LoginActivity.java
package com.myapp.client;
public class SplashActivity extends Activity {
protected boolean _active = true;
protected int _splashTime = 3000; // time to display the splash screen in ms
@Override
public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else
{
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
defaultAccount();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Thread splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while (_active && (waited < _splashTime)) {
sleep(100);
if (_active) {
waited += 100;
}
}
} catch (Exception e) {
} finally {
startActivity(new Intent(SplashActivity.this,
LoginActivity.class));
finish();
}
};
};
splashTread.start();
}
private void defaultAccount(){
PreferencesProviderWrapper prefwrap = new PreferencesProviderWrapper(getApplicationContext());
if (prefwrap.getPreferenceBooleanValue("initialrun", true))
{
//Set the default account
PreferencesWrapper prefs = new PreferencesWrapper(getApplicationContext());
WizardInfo wizardInfo = WizardUtils.getWizardClass("myapp");
WizardIface wizard = null;
try {
wizard = (WizardIface) wizardInfo.classObject.newInstance();
} catch (InstantiationException e) {
Log.e("myapp", "Can't access wizard class", e);
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
Log.e("myapp", "Can't access wizard class", e);
}
prefwrap.setPreferenceBooleanValue("initialrun", false);
SipProfile account = SipProfile.getProfileFromDbId(this, SipProfile.INVALID_ID, DBProvider.ACCOUNT_FULL_PROJECTION);
account = wizard.buildAccount(account);
prefs.startEditing();
wizard.setDefaultParams(prefs);
prefs.endEditing();
account.display_name = "myapp Account";
account.username= "REDACTED";
account.wizard = "myapp";
account = wizard.buildAccount(account);
account.acc_id = "REDACTED";
account.reg_uri = "REDACTED";
account.datatype=0;
account.data="REDACTED";
account.use_rfc5626 = true;
if(true) {
if(TextUtils.isEmpty(account.rfc5626_instance_id)) {
String autoInstanceId = (UUID.randomUUID()).toString();
account.rfc5626_instance_id = "<urn:uuid:"+autoInstanceId+">";
}
}
Uri uri = getContentResolver().insert(SipProfile.ACCOUNT_URI, account.getDbContentValues());
account.id = ContentUris.parseId(uri);
List<Filter> filters = wizard.getDefaultFilters(account);
if (filters != null) {
for (Filter filter : filters) {
// Ensure the correct id if not done by the wizard
filter.account = (int) account.id;
getContentResolver().insert(SipManager.FILTER_URI, filter.getDbContentValues());
}
}
}}
}
然后这是我的LoginActivity.java
package com.myapp.client;
public class LoginActivity extends Activity {
MySQLProvider loginProvider;
Map<String,String> siplogin = null;
EditText username;
EditText password;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else
{
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
username = (EditText)findViewById(R.id.username1);
password = (EditText)findViewById(R.id.password1);
loginProvider= new MySQLProvider(LoginActivity.this);
}
public void loginSubmit(View view){
int responseRecieved = generateResponse();
if (responseRecieved == 0){
setSipLogin(siplogin);
}
generateDialog(responseRecieved);
}
private int generateResponse(){
loginProvider.sqlConnect();
Map<String,String> logininfo = null;
ConnectivityManager cm =(ConnectivityManager)getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
if (!isConnected){return 3;}
if (username.getText().toString() != "" && password.getText().toString() != ""){
logininfo = loginProvider.getLoginInfo(username.getText().toString(), password.getText().toString());
}
else return 2;
if (logininfo.isEmpty() || logininfo == null){
return 1;
}
siplogin = logininfo;
return 0;
}
private void generateDialog(int response){
switch (response){
case 0:
break;
case 1:
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("myapp Login");
alertDialog.setMessage("Username or password is not correct. Please try again.");
alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new Message());
alertDialog.show();
break;
case 2:
AlertDialog alertDialog1 = new AlertDialog.Builder(this).create();
alertDialog1.setTitle("myapp Login");
alertDialog1.setMessage("Please fill the required fields.");
alertDialog1.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new Message());
alertDialog1.show();
break;
case 3:
AlertDialog alertDialog2 = new AlertDialog.Builder(this).create();
alertDialog2.setTitle("myapp Login");
alertDialog2.setMessage("Please provide internet connectivity");
alertDialog2.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new Message());
alertDialog2.show();
break;
}
}
private void setSipLogin(Map<String,String> siplogin){
PreferencesProviderWrapper prefwrap = new PreferencesProviderWrapper(getApplicationContext());
//if (prefwrap.getPreferenceBooleanValue("initialrun", true))
//{
//Set the default account(disabled)
PreferencesWrapper prefs = new PreferencesWrapper(getApplicationContext());
WizardInfo wizardInfo = WizardUtils.getWizardClass("myapp");
WizardIface wizard = null;
try {
wizard = (WizardIface) wizardInfo.classObject.newInstance();
} catch (InstantiationException e) {
Log.e("myapp", "Can't access wizard class", e);
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
Log.e("myapp", "Can't access wizard class", e);
}
//prefwrap.setPreferenceBooleanValue("initialrun", false);
SipProfile account = SipProfile.getProfileFromDbId(this, 1, DBProvider.ACCOUNT_FULL_PROJECTION);
account = wizard.buildAccount(account);
prefs.startEditing();
wizard.setDefaultParams(prefs);
prefs.endEditing();
String[] sipLoginParsed = siplogin.get("info").split(Pattern.quote("#|#|#|#"));
account.display_name = "myapp Account";
account.username= sipLoginParsed[0];
account.wizard = "myapp";
account = wizard.buildAccount(account);
account.acc_id = "REDACTED";
account.reg_uri = "REDACTED";
account.datatype=0;
account.data=sipLoginParsed[1];
account.use_rfc5626 = true;
if(true) {
if(TextUtils.isEmpty(account.rfc5626_instance_id)) {
String autoInstanceId = (UUID.randomUUID()).toString();
account.rfc5626_instance_id = "<urn:uuid:"+autoInstanceId+">";
}
}
Uri uri = getContentResolver().insert(SipProfile.ACCOUNT_URI, account.getDbContentValues());
account.id = ContentUris.parseId(uri);
List<Filter> filters = wizard.getDefaultFilters(account);
if (filters != null) {
for (Filter filter : filters) {
// Ensure the correct id if not done by the wizard
filter.account = (int) account.id;
getContentResolver().insert(SipManager.FILTER_URI, filter.getDbContentValues());
}
}
startActivity(new Intent(LoginActivity.this,SipHome.class));
}
}
//}
最后这是我的Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.client"
android:installLocation="auto"
android:versionCode="2459"
android:versionName="1.02.03" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="22" />
<application
android:allowBackup="true"
android:backupAgent=".backup.SipBackupAgent"
android:hardwareAccelerated="true"
android:icon="@drawable/ic_launcher_nightly"
android:label="myapp" >
<!--
<activity
android:name=".ui.SipHome"
android:label="@string/app_name"
android:launchMode="singleTask"
android:theme="@style/DarkTheme"
android:uiOptions="splitActionBarWhenNarrow" >
<intent-filter android:priority="10" >
<action android:name="com.myapp.client.phone.action.DIALER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter android:priority="10" >
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sip" />
<data android:scheme="csip" />
</intent-filter>
<intent-filter android:priority="10" >
<action android:name="com.myapp.client.phone.action.CALLLOG" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter android:priority="10" >
<action android:name="com.myapp.client.phone.action.FAVORITES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter android:priority="10" >
<action android:name="com.myapp.client.phone.action.MESSAGES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity-alias
android:name=".ui.SipDialer"
android:label="@string/app_name"
android:launchMode="singleTask"
android:targetActivity=".ui.SipHome"
android:theme="@style/DarkTheme"
android:uiOptions="splitActionBarWhenNarrow" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="csip" />
<data android:scheme="sip" />
<data android:scheme="sips" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="csip"
android:scheme="imto" />
<data
android:host="sip"
android:scheme="imto" />
<data
android:host="skype"
android:scheme="imto" />
</intent-filter>
</activity-alias>
<!-- Main service -->
<!-- Require at least the configure permission to use -->
<service
android:name=".service.SipService"
android:exported="true"
android:permission="android.permission.CONFIGURE_SIP"
android:process=":sipStack" >
<intent-filter>
<action android:name="com.myapp.client.service.SipService" />
<action android:name="com.myapp.client.service.SipConfiguration" />
</intent-filter>
</service>
<service android:name=".service.Downloader" />
<!-- Main ui -->
<activity
android:name=".ui.calllog.CallLogDetailsActivity"
android:theme="@style/DarkTheme" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ui.prefs.cupcake.MainPrefs"
android:configChanges="orientation"
android:enabled="@bool/use_cupcake_prefs"
android:label="@string/prefs"
android:permission="android.permission.CONFIGURE_SIP"
android:theme="@style/DarkTheme" >
<intent-filter>
<action android:name="com.myapp.client.ui.action.PREFS_GLOBAL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ui.prefs.cupcake.PrefsLoaderActivity"
android:label=""
android:theme="@style/DarkTheme" />
<activity
android:name=".ui.prefs.PrefsFilters"
android:configChanges="orientation"
android:label="@string/filters"
android:theme="@style/DarkTheme" />
<activity
android:name=".ui.prefs.PrefsFast"
android:configChanges="orientation"
android:label="@string/prefs_fast"
android:permission="android.permission.CONFIGURE_SIP"
android:theme="@style/DarkTheme.Dialog" >
<intent-filter>
<action android:name="com.myapp.client.ui.action.PREFS_FAST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ui.prefs.Codecs"
android:configChanges="orientation"
android:label="@string/codecs"
android:theme="@style/DarkTheme" />
<activity
android:name=".ui.prefs.AudioTester"
android:label="@string/test_audio"
android:screenOrientation="portrait"
android:theme="@style/DarkTheme.Dialog" />
<!-- Wizards -->
<activity
android:name=".wizards.BasePrefsWizard"
android:configChanges="orientation"
android:label="@string/edit"
android:theme="@style/DarkTheme" />
<!-- Call management -->
<receiver
android:name=".service.OutgoingCall"
android:permission="android.permission.CALL_PHONE"
android:process=":sipStack" >
<!-- Here filter for protected-broadcasts -->
<intent-filter android:priority="0" >
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
<activity
android:name=".ui.outgoingcall.OutgoingCallChooser"
android:allowTaskReparenting="false"
android:configChanges="orientation"
android:excludeFromRecents="true"
android:label="@string/call"
android:launchMode="singleTask"
android:permission="android.permission.USE_SIP"
android:process=":sipStack"
android:taskAffinity=""
android:theme="@style/DarkTheme.Dialog" >
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="csip" />
<data android:scheme="sip" />
<data android:scheme="sips" />
</intent-filter>
<intent-filter android:priority="10" >
<action android:name="android.phone.extra.NEW_CALL_INTENT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="csip" />
<data android:scheme="sip" />
<data android:scheme="sips" />
</intent-filter>
</activity>
<activity-alias
android:name=".ui.PrivilegedOutgoingSipCallBroadcaster"
android:configChanges="orientation"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:permission="android.permission.CALL_PRIVILEGED"
android:targetActivity=".ui.outgoingcall.OutgoingCallChooser"
android:theme="@style/DarkTheme.Dialog" >
<intent-filter>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sip" />
</intent-filter>
</activity-alias>
<activity-alias
android:name=".ui.PrivilegedOutgoingCallBroadcaster"
android:configChanges="orientation"
android:enabled="false"
android:excludeFromRecents="true"
android:label="@string/sip_call"
android:launchMode="singleTask"
android:permission="android.permission.CALL_PRIVILEGED"
android:targetActivity=".ui.outgoingcall.OutgoingCallChooser"
android:theme="@style/DarkTheme.Dialog" >
<intent-filter>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/phone" />
<data android:mimeType="vnd.android.cursor.item/phone_v2" />
<data android:mimeType="vnd.android.cursor.item/person" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
</intent-filter>
</activity-alias>
<!-- To be able to do video, this has to be launched in sipStack process -->
<activity
android:name=".ui.incall.InCallActivity"
android:allowTaskReparenting="true"
android:configChanges="orientation"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:permission="android.permission.CONFIGURE_SIP"
android:process=":sipStack"
android:taskAffinity=""
android:theme="@style/DarkTheme.NoTitle" >
<intent-filter android:priority="10" >
<action android:name="com.myapp.client.phone.action.INCALL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ui.PickupSipUri"
android:configChanges="orientation"
android:label="@string/pickup_sip_uri"
android:theme="@style/DarkTheme" />
<activity
android:name=".ui.incall.InCallMediaControl"
android:configChanges="orientation"
android:label="@string/prefs_media"
android:taskAffinity="com.myapp.client.ui.incall.InCallActivity"
android:theme="@style/DarkTheme.Dialog" />
<!-- New UI -->
<activity
android:name=".ui.account.AccountsEditList"
android:label="@string/accounts"
android:theme="@style/DarkTheme" />
<activity
android:name=".ui.account.AccountEdit"
android:theme="@style/DarkTheme" />
<activity
android:name=".SplashActivity"
android:label="@string/app_name"
android:noHistory="true"
android:theme="@style/Theme.Sherlock.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:noHistory="true"
android:configChanges="orientation"
android:label="LoginActivity" />
</application>
</manifest>
Android Manifest和部分代码被编辑为30000个字符。(接收者和提供者也导入) 当我尝试从活动启动器应用程序启动任何活动时也会发生同样的错误。
答案 0 :(得分:1)
您缺少在Manifest中声明LoginActivity。
<activity
android:name=".LoginActivity"
android:configChanges="orientation"
android:label="LoginActivity" />
如果没有宣布活动,根本无法启动活动。
答案 1 :(得分:0)
就像你指出的那样,我认为错误的发生是因为LoginActivity不包含在AndroidManifest中的Activity中