Итак, я пытаюсь создать общую настройку, и приложение работает нормально, и внезапно оно сломалось.Общие предпочтения - это замораживание моего приложения - Android-приложение для Android
Я сунул его вниз до точной линии, нарушающей код, и я точно не знаю, как это исправить.
Любые предложения?
Вот мой текущий код:
public class studentEmail extends Activity {
private WebView mWebview;
public static final String PREFS_NAME = "MyPrefsFile";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.student_email) ;
final SharedPreferences preferences = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
mWebview = new WebView(this);
final EditText emEdit = (EditText)findViewById(R.id.editEmail);
final EditText passEdit = (EditText)findViewById(R.id.editPass);
if(preferences.getString("username", null).isEmpty() && preferences.getString("password", null).isEmpty())
{
mWebview = new WebView(this);
mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
final Activity activity = this;
mWebview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}
});
Toast.makeText(getApplicationContext(), "Preference is empty :)", Toast.LENGTH_SHORT).show();
TextView text = (TextView)findViewById(R.id.textView1);
TextView textEmail = (TextView)findViewById(R.id.textViewEmail);
TextView textPass = (TextView)findViewById(R.id.textViewPass);
TextView textTitle = (TextView)findViewById(R.id.textViewTitle);
text.setTypeface(null, Typeface.BOLD_ITALIC);
textEmail.setTypeface(null, Typeface.BOLD_ITALIC);
textPass.setTypeface(null, Typeface.BOLD_ITALIC);
textTitle.setTypeface(null, Typeface.BOLD_ITALIC);
text.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX,26);
textEmail.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX,26);
textPass.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX,26);
textTitle.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, 40);
textTitle.setText("E-mail Login");
text.setText("\n\nPlease enter your Student E-mail and Password.\n");
textEmail.setText("E-Mail:");
textPass.setText("\nPassword:");
final EditText emailValidate = (EditText)findViewById(R.id.editEmail);
final TextView emailValMsg = (TextView)findViewById(R.id.emailValidate);
final EditText password = (EditText)findViewById(R.id.editPass);
emailValidate.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void afterTextChanged(Editable s) {
String email = emailValidate.getText().toString().trim();
String emailPattern = "[a-zA-Z0-9._-][email protected]+\\.+itsligo+\\.+ie+";
if (email.matches(emailPattern) && s.length() > 0)
{
Toast.makeText(getApplicationContext(), "Your e-mail is now valid! :)", Toast.LENGTH_SHORT).show();
// or
emailValMsg.setText("Valid email");
}
else
{
emailValMsg.setText("Invalid email !");
}
}
});
final Button button = (Button) findViewById(R.id.loginButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String email = emailValidate.getText().toString().trim();
String emailPattern = "[a-zA-Z0-9._-][email protected][a-z]+\\.+[a-z]+";
if (emailValidate.getText().toString().trim().matches("") || password.getText().toString().trim().matches("")) {
if (emailValidate.getText().toString().trim().matches("") && password.getText().toString().trim().matches("")) {
Toast.makeText(getApplicationContext(), "Please enter an E-mail Address and Password", Toast.LENGTH_SHORT).show();
} else if (emailValidate.getText().toString().trim().matches("")) {
Toast.makeText(getApplicationContext(), "Please enter an E-mail Address", Toast.LENGTH_SHORT).show();
} else if (password.getText().toString().trim().matches("")) {
Toast.makeText(getApplicationContext(), "Please enter a Password", Toast.LENGTH_SHORT).show();
}
}
else {
mWebview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
String webUrl = mWebview.getUrl();
CheckBox cbox1 = (CheckBox)findViewById(R.id.checkbox_store);
if (cbox1.isChecked())
{
}
mWebview.loadUrl("javascript:(function() { " + "document.getElementById('cred_userid_inputtext').value ='" + emEdit.getText() + "';" + "})()");
mWebview.loadUrl("javascript:(function() { " + "document.getElementById('cred_password_inputtext').value ='" + passEdit.getText() + "';" + "})()");
mWebview.loadUrl("javascript:(function() { " + "document.getElementById('credentials').submit(); return false;" + "})()");
}
});
mWebview.loadUrl("http://login.microsoftonline.com");
setContentView(mWebview);
Toast.makeText(getApplicationContext(), "This works!", Toast.LENGTH_SHORT).show();
}
}
});
}
else
{
mWebview = new WebView(this);
mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
final Activity activity = this;
mWebview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}
});
mWebview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
String webUrl = mWebview.getUrl();
mWebview.loadUrl("javascript:(function() { " + "document.getElementById('cred_userid_inputtext').value ='" + preferences.getString("username", null).toString() + "';" + "})()");
mWebview.loadUrl("javascript:(function() { " + "document.getElementById('cred_password_inputtext').value ='" + preferences.getString("password", null).toString() + "';" + "})()");
mWebview.loadUrl("javascript:(function() { " + "document.getElementById('credentials').submit(); return false;" + "})()");
}
});
mWebview.loadUrl("http://login.microsoftonline.com");
setContentView(mWebview);
Toast.makeText(getApplicationContext(), "Preferences have something", Toast.LENGTH_SHORT).show();
}
}
}
Ошибки:
02-14 19:20:06.130 632-632/com.example.PorjectStudent E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.PorjectStudent/com.example.PorjectStudent.studentEmail}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
02-14 19:20:06.130 632-632/com.example.PorjectStudent E/AndroidRuntime﹕ FATAL EXCEPTION: main
at com.example.PorjectStudent.studentEmail.onCreate(studentEmail.java:35)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
02-14 19:42:37.971 677-677/com.example.PorjectStudent E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.PorjectStudent/com.example.PorjectStudent.studentEmail}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.PorjectStudent.studentEmail.onCreate(studentEmail.java:39)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Я действительно тупик и решение, вероятно просто, но это было вредительством мой мозг весь день, так что я решил обратиться за помощью поскольку я не прогрессировал в часах!
Спасибо за любую помощь :)
Можете ли вы добавить трассировку стека исключений на свой вопрос? – elevine
Это ваш ** полный ** stacktracke? Необходимо добавить его полностью, так как теперь могут быть не показаны детали. – nKn
Это полная вещь на данный момент! Больше ничего не видно! –