2015-04-22 5 views
0

Я совершенно новый для Android-разработки, и это первый день, когда я когда-либо касался студии Android. Я реализую приложение для заметок, в котором есть страница настроек, которая помогает пользователям изменять цвет текста. На странице настроек есть 3 переключателя (3 цвета), содержащихся в группе радио, и кнопка сохранения, чтобы сохранить настройки. Когда нажата кнопка сохранения, она изменит цвет текста в другом файле layout/xml под названием NoteEditor. когда я попытался запустить приложение, я нажал кнопку «Сохранить». Я уже регистрирую класс настроек в AndroidManifest Пожалуйста, помогите !!Android-приложение остановилось при нажатии кнопки

Ниже мой код

Settings.Java

package com.example.sunny.mynote; 

import android.app.Activity; 
import android.content.Intent; 
import android.graphics.Color; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.Window; 
import android.widget.Button; 
import android.widget.RadioButton; 
import android.widget.RadioGroup; 
import android.widget.TextView; 
import android.widget.Toast; 
import android.widget.EditText; 

/** 
* Created by Sunny on 19/04/2015. 
*/ 
public class Settings extends Activity { 

    private RadioGroup RadioGroup1; 
    private RadioButton rdbRed, rdbBlue, rdbOrange; 
    private Button btnSave; 
    private EditText textView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_ACTION_BAR); 
     setContentView(R.layout.settings); 
     View view = LayoutInflater.from(getApplication()).inflate(R.layout.settings, null); 

     RadioGroup1 = (RadioGroup) findViewById(R.id.RadioGroup1); 

     RadioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(RadioGroup group, int checkedId) { 
       if(checkedId == R.id.rdbRed) 
       { 
        Toast.makeText(getApplicationContext(), "choice: Red", 
          Toast.LENGTH_SHORT).show(); 
        RadioGroup1.check(R.id.rdbRed); 
       } 
       else if(checkedId == R.id.rdbBlue) 
       { 
        Toast.makeText(getApplicationContext(), "choice: Blue", 
          Toast.LENGTH_SHORT).show(); 
        RadioGroup1.check(R.id.rdbBlue); 
       } 
       else 
       { 
        Toast.makeText(getApplicationContext(), "choice: Orange", 
          Toast.LENGTH_SHORT).show(); 
        RadioGroup1.check(R.id.rdbOrange); 
       } 
      } 
     }); 

     rdbRed = (RadioButton) findViewById(R.id.rdbRed); 
     rdbBlue = (RadioButton) findViewById(R.id.rdbBlue); 
     rdbOrange = (RadioButton) findViewById(R.id.rdbOrange); 
     textView = (EditText) findViewById(R.id.noteText); 
     btnSave = (Button)findViewById(R.id.btn_Save); 
     btnSave.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       int selectedId = RadioGroup1.getCheckedRadioButtonId(); 
        if(selectedId == rdbRed.getId()) { 
         String color1 = String.valueOf(Color.parseColor("#FF0000")); 
         String color2 = String.valueOf(Color.parseColor("#FF0000")); 
         String color3 = String.valueOf(Color.parseColor("#FF0000")); 

         Intent intent = new Intent(this, NoteEditorActivity.class); 
         intent.putExtra("textValue", color1); 
         intent.putExtra("textValue1", color2); 
         intent.putExtra("textValue2", color3); 
         startActivity(intent); 
       } else if(selectedId == rdbBlue.getId()) { 
        textView.setTextColor(Color.parseColor("#0066FF")); 
       } else { 
        textView.setTextColor(Color.parseColor("#FF6600")); 
       } 
      } 

     }); 

    } 

    @Override 
    public void onBackPressed() { 
     super.onBackPressed(); 
     finish(); 
    } 
} 

NoteEditorActivity.Java

package com.example.sunny.mynote; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.MenuItem; 
import android.widget.EditText; 

import com.example.sunny.mynote.com.example.sunny.mynote.data.NoteItem; 

/** 
* Created by Sunny on 19/04/2015. 
*/ 
public class NoteEditorActivity extends Activity { 

    private NoteItem note; 
    private String textValue1; 
    private String textValue2; 
    private String textValue3; 

    EditText textView = (EditText) findViewById(R.id.noteText); 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_note_editor); 
     getActionBar().setDisplayHomeAsUpEnabled(true); 

     Intent intent = this.getIntent(); 
     note = new NoteItem(); 
     note.setKey(intent.getStringExtra("key")); 
     note.setText(intent.getStringExtra("text")); 

     EditText et = (EditText) findViewById(R.id.noteText); 
     et.setText(note.getText()); 
     et.setSelection(note.getText().length()); 

     //Intent intent = getIntent(); 
     textValue1 = intent.getStringExtra("textValue"); 
     textValue2 = intent.getStringExtra("textValue1"); 
     textValue3 = intent.getStringExtra("textValue2"); 

     if(textValue1 != null){ 
      textView.setText(textValue1); 
     } 
     else if (textValue2 != null){ 
      textView.setText(textValue2); 
     } 
     else { 
      textView.setText(textValue3); 
     } 
    } 

    private void saveAndFinish() 
    { 
     EditText et = (EditText) findViewById(R.id.noteText); 
     String noteText = et.getText().toString(); 

     Intent intent = new Intent(); 
     intent.putExtra("key", note.getKey()); 
     intent.putExtra("text", noteText); 
     setResult(RESULT_OK, intent); 

     finish(); 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     if (item.getItemId() == android.R.id.home) 
     { 
      saveAndFinish(); 
     } 
     return false; 
    } 

    @Override 
    public void onBackPressed() { 
     saveAndFinish(); 
    } 
} 

Logcat

04-22 20:45:11.283 30609-30609/com.example.sunny.mynote D/AbsListView﹕ Get MotionRecognitionManager 
04-22 20:45:11.303 30609-30609/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:11.353 30609-30609/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:11.353 30609-30609/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:11.383 30609-30609/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:11.393 30609-30609/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:12.433 30609-30609/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:12.433 30609-30609/com.example.sunny.mynote D/AbsListView﹕ onDetachedFromWindow 
04-22 20:45:12.433 30609-30609/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:12.443 30609-30609/com.example.sunny.mynote W/ApplicationPackageManager﹕ getCSCPackageItemText() 
04-22 20:45:12.453 30609-30609/com.example.sunny.mynote E/MoreInfoHPW_ViewGroup﹕ Parent view is not a TextView 
04-22 20:45:12.783 30609-30609/com.example.sunny.mynote D/AbsListView﹕ onVisibilityChanged() is called, visibility : 4 
04-22 20:45:12.783 30609-30609/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:17.233 30609-30609/com.example.sunny.mynote D/AndroidRuntime﹕ Shutting down VM 
04-22 20:45:17.233 30609-30609/com.example.sunny.mynote W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x417e0da0) 
04-22 20:45:17.243 30609-30609/com.example.sunny.mynote E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    Process: com.example.sunny.mynote, PID: 30609 
    java.lang.NullPointerException 
      at com.example.sunny.mynote.Settings.saveButtonPressed(Settings.java:36) 
      at com.example.sunny.mynote.Settings.access$100(Settings.java:19) 
      at com.example.sunny.mynote.Settings$2.onClick(Settings.java:84) 
      at android.view.View.performClick(View.java:4630) 
      at android.view.View$PerformClick.run(View.java:19339) 
      at android.os.Handler.handleCallback(Handler.java:733) 
      at android.os.Handler.dispatchMessage(Handler.java:95) 
      at android.os.Looper.loop(Looper.java:157) 
      at android.app.ActivityThread.main(ActivityThread.java:5335) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) 
      at dalvik.system.NativeStart.main(Native Method) 
04-22 20:45:18.573 30609-30609/com.example.sunny.mynote I/Process﹕ Sending signal. PID: 30609 SIG: 9 
04-22 20:45:18.633 31515-31515/com.example.sunny.mynote I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file. 
04-22 20:45:18.653 31515-31515/com.example.sunny.mynote I/SELinux﹕ Function: selinux_android_load_priority , spota verifySig and checkHash pass. priority version is VE=SEPF_SM-N9005_4.4.2_0040 
04-22 20:45:18.653 31515-31515/com.example.sunny.mynote I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /data/security/spota/seapp_contexts 
04-22 20:45:18.653 31515-31515/com.example.sunny.mynote E/dalvikvm﹕ >>>>> Normal User 
04-22 20:45:18.653 31515-31515/com.example.sunny.mynote E/dalvikvm﹕ >>>>> com.example.sunny.mynote [ userId:0 | appId:10383 ] 
04-22 20:45:18.653 31515-31515/com.example.sunny.mynote D/dalvikvm﹕ Late-enabling CheckJNI 
04-22 20:45:18.673 31515-31515/com.example.sunny.mynote I/dalvikvm﹕ Enabling JNI app bug workarounds for target SDK version 7... 
04-22 20:45:18.743 31515-31515/com.example.sunny.mynote W/ApplicationPackageManager﹕ getCSCPackageItemText() 
04-22 20:45:18.743 31515-31515/com.example.sunny.mynote I/PersonaManager﹕ getPersonaService() name persona_policy 
04-22 20:45:18.783 31515-31515/com.example.sunny.mynote E/MoreInfoHPW_ViewGroup﹕ Parent view is not a TextView 
04-22 20:45:18.813 31515-31515/com.example.sunny.mynote D/AndroidRuntime﹕ Shutting down VM 
04-22 20:45:18.813 31515-31515/com.example.sunny.mynote W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x417e0da0) 
04-22 20:45:18.813 31515-31515/com.example.sunny.mynote E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    Process: com.example.sunny.mynote, PID: 31515 
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sunny.mynote/com.example.sunny.mynote.NoteEditorActivity}: java.lang.NullPointerException 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350) 
      at android.app.ActivityThread.access$800(ActivityThread.java:163) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:157) 
      at android.app.ActivityThread.main(ActivityThread.java:5335) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) 
      at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.NullPointerException 
      at com.example.sunny.mynote.NoteEditorActivity.onCreate(NoteEditorActivity.java:53) 
      at android.app.Activity.performCreate(Activity.java:5389) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2256) 
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350) 
            at android.app.ActivityThread.access$800(ActivityThread.java:163) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257) 
            at android.os.Handler.dispatchMessage(Handler.java:102) 
            at android.os.Looper.loop(Looper.java:157) 
            at android.app.ActivityThread.main(ActivityThread.java:5335) 
            at java.lang.reflect.Method.invokeNative(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:515) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) 
            at dalvik.system.NativeStart.main(Native Method) 
04-22 20:45:21.793 31515-31515/com.example.sunny.mynote I/Process﹕ Sending signal. PID: 31515 SIG: 9 
04-22 20:45:22.033 31846-31846/com.example.sunny.mynote W/ApplicationPackageManager﹕ getCSCPackageItemText() 
04-22 20:45:22.043 31846-31846/com.example.sunny.mynote I/PersonaManager﹕ getPersonaService() name persona_policy 
04-22 20:45:22.093 31846-31846/com.example.sunny.mynote E/MoreInfoHPW_ViewGroup﹕ Parent view is not a TextView 
04-22 20:45:22.103 31846-31846/com.example.sunny.mynote D/AbsListView﹕ Get MotionRecognitionManager 
04-22 20:45:22.123 31846-31846/com.example.sunny.mynote D/AbsListView﹕ onVisibilityChanged() is called, visibility : 4 
04-22 20:45:22.123 31846-31846/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:22.143 31846-31846/com.example.sunny.mynote D/AbsListView﹕ onVisibilityChanged() is called, visibility : 0 
04-22 20:45:22.143 31846-31846/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:22.153 31846-31846/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:22.173 31846-31846/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:22.173 31846-31846/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:22.203 31846-31846/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:23.623 31846-31846/com.example.sunny.mynote D/AbsListView﹕ Get MotionRecognitionManager 
04-22 20:45:23.643 31846-31846/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:23.713 31846-31846/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:23.713 31846-31846/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:23.733 31846-31846/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:23.763 31846-31846/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:24.723 31846-31846/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:24.723 31846-31846/com.example.sunny.mynote D/AbsListView﹕ onDetachedFromWindow 
04-22 20:45:24.723 31846-31846/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:24.723 31846-31846/com.example.sunny.mynote W/ApplicationPackageManager﹕ getCSCPackageItemText() 
04-22 20:45:24.743 31846-31846/com.example.sunny.mynote E/MoreInfoHPW_ViewGroup﹕ Parent view is not a TextView 
04-22 20:45:25.073 31846-31846/com.example.sunny.mynote D/AbsListView﹕ onVisibilityChanged() is called, visibility : 4 
04-22 20:45:25.073 31846-31846/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:26.593 31846-31846/com.example.sunny.mynote D/AndroidRuntime﹕ Shutting down VM 
04-22 20:45:26.593 31846-31846/com.example.sunny.mynote W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x417e0da0) 
04-22 20:45:26.593 31846-31846/com.example.sunny.mynote E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    Process: com.example.sunny.mynote, PID: 31846 
    java.lang.NullPointerException 
      at com.example.sunny.mynote.Settings.saveButtonPressed(Settings.java:36) 
      at com.example.sunny.mynote.Settings.access$100(Settings.java:19) 
      at com.example.sunny.mynote.Settings$2.onClick(Settings.java:84) 
      at android.view.View.performClick(View.java:4630) 
      at android.view.View$PerformClick.run(View.java:19339) 
      at android.os.Handler.handleCallback(Handler.java:733) 
      at android.os.Handler.dispatchMessage(Handler.java:95) 
      at android.os.Looper.loop(Looper.java:157) 
      at android.app.ActivityThread.main(ActivityThread.java:5335) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) 
      at dalvik.system.NativeStart.main(Native Method) 
04-22 20:45:31.993 31846-31846/com.example.sunny.mynote I/Process﹕ Sending signal. PID: 31846 SIG: 9 
04-22 20:45:32.193 32455-32455/com.example.sunny.mynote W/ApplicationPackageManager﹕ getCSCPackageItemText() 
04-22 20:45:32.193 32455-32455/com.example.sunny.mynote I/PersonaManager﹕ getPersonaService() name persona_policy 
04-22 20:45:32.223 32455-32455/com.example.sunny.mynote E/MoreInfoHPW_ViewGroup﹕ Parent view is not a TextView 
04-22 20:45:32.243 32455-32455/com.example.sunny.mynote D/AbsListView﹕ Get MotionRecognitionManager 
04-22 20:45:32.253 32455-32455/com.example.sunny.mynote D/AbsListView﹕ onVisibilityChanged() is called, visibility : 4 
04-22 20:45:32.253 32455-32455/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:32.263 32455-32455/com.example.sunny.mynote D/AbsListView﹕ onVisibilityChanged() is called, visibility : 0 
04-22 20:45:32.263 32455-32455/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:32.273 32455-32455/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:32.293 32455-32455/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:32.313 32455-32455/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:32.323 32455-32455/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:33.533 32455-32455/com.example.sunny.mynote D/AbsListView﹕ Get MotionRecognitionManager 
04-22 20:45:33.553 32455-32455/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:33.603 32455-32455/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:33.603 32455-32455/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:33.643 32455-32455/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:33.643 32455-32455/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:34.423 32455-32455/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:34.423 32455-32455/com.example.sunny.mynote D/AbsListView﹕ onDetachedFromWindow 
04-22 20:45:34.423 32455-32455/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:34.433 32455-32455/com.example.sunny.mynote W/ApplicationPackageManager﹕ getCSCPackageItemText() 
04-22 20:45:34.443 32455-32455/com.example.sunny.mynote E/MoreInfoHPW_ViewGroup﹕ Parent view is not a TextView 
04-22 20:45:34.753 32455-32455/com.example.sunny.mynote D/AbsListView﹕ onVisibilityChanged() is called, visibility : 4 
04-22 20:45:34.753 32455-32455/com.example.sunny.mynote D/AbsListView﹕ unregisterIRListener() is called 
04-22 20:45:38.373 32455-32455/com.example.sunny.mynote D/AndroidRuntime﹕ Shutting down VM 
04-22 20:45:38.373 32455-32455/com.example.sunny.mynote W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x417e0da0) 
04-22 20:45:38.373 32455-32455/com.example.sunny.mynote E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    Process: com.example.sunny.mynote, PID: 32455 
    java.lang.NullPointerException 
      at com.example.sunny.mynote.Settings.saveButtonPressed(Settings.java:36) 
      at com.example.sunny.mynote.Settings.access$100(Settings.java:19) 
      at com.example.sunny.mynote.Settings$2.onClick(Settings.java:84) 
      at android.view.View.performClick(View.java:4630) 
      at android.view.View$PerformClick.run(View.java:19339) 
      at android.os.Handler.handleCallback(Handler.java:733) 
      at android.os.Handler.dispatchMessage(Handler.java:95) 
      at android.os.Looper.loop(Looper.java:157) 
      at android.app.ActivityThread.main(ActivityThread.java:5335) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) 
      at dalvik.system.NativeStart.main(Native Method) 
04-22 20:45:39.763 32455-32455/com.example.sunny.mynote I/Process﹕ Sending signal. PID: 32455 SIG: 9 
04-22 20:45:39.953 32526-32526/com.example.sunny.mynote W/ApplicationPackageManager﹕ getCSCPackageItemText() 
04-22 20:45:39.953 32526-32526/com.example.sunny.mynote I/PersonaManager﹕ getPersonaService() name persona_policy 
04-22 20:45:39.973 32526-32526/com.example.sunny.mynote E/MoreInfoHPW_ViewGroup﹕ Parent view is not a TextView 
04-22 20:45:40.003 32526-32526/com.example.sunny.mynote D/AndroidRuntime﹕ Shutting down VM 
04-22 20:45:40.003 32526-32526/com.example.sunny.mynote W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x417e0da0) 
04-22 20:45:40.003 32526-32526/com.example.sunny.mynote E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    Process: com.example.sunny.mynote, PID: 32526 
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sunny.mynote/com.example.sunny.mynote.NoteEditorActivity}: java.lang.NullPointerException 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350) 
      at android.app.ActivityThread.access$800(ActivityThread.java:163) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:157) 
      at android.app.ActivityThread.main(ActivityThread.java:5335) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) 
      at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.NullPointerException 
      at com.example.sunny.mynote.NoteEditorActivity.onCreate(NoteEditorActivity.java:53) 
      at android.app.Activity.performCreate(Activity.java:5389) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2256) 
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350) 
            at android.app.ActivityThread.access$800(ActivityThread.java:163) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257) 
            at android.os.Handler.dispatchMessage(Handler.java:102) 
            at android.os.Looper.loop(Looper.java:157) 
            at android.app.ActivityThread.main(ActivityThread.java:5335) 
            at java.lang.reflect.Method.invokeNative(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:515) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) 
            at dalvik.system.NativeStart.main(Native Method) 
+0

Можете ли вы просто ввести журнал ошибок, а не все лог-код, чтобы было легко понять, где это неправильно. – Codelord

+0

, пожалуйста, напишите полный [logcat] (https://politecuriosity.files.wordpress.com/2013/05/logcat.jpg). – Gattsu

+0

есть ли текстовое изображение в настройке.xml ?? Пожалуйста, напишите settings.xml – Jaydeep

ответ

0

Да вы получаете нулевой указатель есть клюв ause вы находитесь в классе настроек, и вы инициализируете текстовое представление, но текстовое представление находится в классе NoteEditor. Инициализировать текстовое представление в классе NoteEditor.

Следующая строка должна быть в классе NoteEditor:

EditText textView = (EditText) findViewById(R.id.noteText); 

Вы просто создать объект намерения, а не создание объекта намерения необходимо отправить текстовое значение для класса NoteEditor, а затем установите текст, как показано ниже:

Выполните следующие действия в методе OnClick удалите следующую строку:

textView.setTextColor(Color.parseColor("#FF0000")); 

изменить приведенные выше строки, как показано ниже:

String color1 = String.valueOf(Color.parseColor("#FF0000")); 
String color2 = String.valueOf(Color.parseColor("#FF0000")); 
String color3 = String.valueOf(Color.parseColor("#FF0000")); 

    Intent intent = new Intent(this, NoteEditorActivity.class); 
    intent.putExtra("textValue", color1); 
intent.putExtra("textValue1", color2); 
intent.putExtra("textValue2", color3); 
startActivity(intent); 

После этого в классе Примечание редактора выполните следующие действия:

Intent intent = getIntent(); 
    textValue1 = intent.getStringExtra("textValue"); 
textValue2 = intent.getStringExtra("textValue1"); 
textValue3 = intent.getStringExtra("textValue2"); 

if(textValue1 != null){ 
    textView.setText(textValue1); 
} 
else if (textValue2 != null){ 
    textView.setText(textValue2); 
} 
else { 
textView.setText(textValue3); 
} 

Изменить свой Settings.java в код, показанный ниже, скопируйте следующий код из строки я поставил здесь и вставить его, не удалить полный код в классе быть осторожным при копировании:

public class Settings extends Activity { 

     private RadioGroup RadioGroup1; 
     private RadioButton rdbRed, rdbBlue, rdbOrange; 
     private Button btnSave; 
    private String color1, color2, color3; 


     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      requestWindowFeature(Window.FEATURE_ACTION_BAR); 
      setContentView(R.layout.settings); 

      RadioGroup1 = (RadioGroup) findViewById(R.id.RadioGroup1); 

      RadioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
       @Override 
       public void onCheckedChanged(RadioGroup group, int checkedId) { 
        if(checkedId == R.id.rdbRed) 
        { 
         Toast.makeText(getApplicationContext(), "choice: Red", 
           Toast.LENGTH_SHORT).show(); 
         RadioGroup1.check(R.id.rdbRed); 
        } 
        else if(checkedId == R.id.rdbBlue) 
        { 
         Toast.makeText(getApplicationContext(), "choice: Blue", 
           Toast.LENGTH_SHORT).show(); 
         RadioGroup1.check(R.id.rdbBlue); 
        } 
        else 
        { 
         Toast.makeText(getApplicationContext(), "choice: Orange", 
           Toast.LENGTH_SHORT).show(); 
         RadioGroup1.check(R.id.rdbOrange); 
        } 
       } 
      }); 

      rdbRed = (RadioButton) findViewById(R.id.rdbRed); 
      rdbBlue = (RadioButton) findViewById(R.id.rdbBlue); 
      rdbOrange = (RadioButton) findViewById(R.id.rdbOrange); 
        btnSave = (Button)findViewById(R.id.btn_Save); 
      btnSave.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        int selectedId = RadioGroup1.getCheckedRadioButtonId(); 
         if(selectedId == rdbRed.getId()) { 
          color1 = String.valueOf(Color.parseColor("#FF0000")); 

              } 
else if(selectedId == rdbBlue.getId()) { 
      color2 = String.valueOf(Color.parseColor("#0066FF")); 
        } 
else { 
       color3 = String.valueOf(Color.parseColor("#FF6600")); 
        } 
       } 

      }); 

    Intent intent = new Intent(this, NoteEditorActivity.class); 
          intent.putExtra("textValue", color1); 
          intent.putExtra("textValue1", color2); 
          intent.putExtra("textValue2", color3); 
          startActivity(intent); 


     } 

     @Override 
     public void onBackPressed() { 
      super.onBackPressed(); 
      finish(); 
     } 

не удалить какой-либо код, который уже присутствует выше линии общественного класса.

Аналогично скопируйте приведенный ниже код и вставьте его в классе NoteEditor:

public class NoteEditorActivity extends Activity { 

    private NoteItem note; 
    private String textValue1; 
    private String textValue2; 
    private String textValue3; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_note_editor); 
     getActionBar().setDisplayHomeAsUpEnabled(true); 

EditText textView = (EditText) findViewById(R.id.noteText); 


     Intent intent = this.getIntent(); 
     note = new NoteItem(); 
     note.setKey(intent.getStringExtra("key")); 
     note.setText(intent.getStringExtra("text")); 

     EditText et = (EditText) findViewById(R.id.noteText); 
     et.setText(note.getText()); 
     et.setSelection(note.getText().length()); 

     //Intent intent = getIntent(); 
     textValue1 = intent.getStringExtra("textValue"); 
     textValue2 = intent.getStringExtra("textValue1"); 
     textValue3 = intent.getStringExtra("textValue2"); 

     if(textValue1 != null){ 
      textView.setText(textValue1); 
     } 
     else if (textValue2 != null){ 
      textView.setText(textValue2); 
     } 
     else { 
      textView.setText(textValue3); 
     } 
    } 

    private void saveAndFinish() 
    { 
     EditText et = (EditText) findViewById(R.id.noteText); 
     String noteText = et.getText().toString(); 

     Intent intent = new Intent(); 
     intent.putExtra("key", note.getKey()); 
     intent.putExtra("text", noteText); 
     setResult(RESULT_OK, intent); 

     finish(); 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     if (item.getItemId() == android.R.id.home) 
     { 
      saveAndFinish(); 
     } 
     return false; 
    } 

    @Override 
    public void onBackPressed() { 
     saveAndFinish(); 
    } 
} 

Позвольте мне знать, после того, как делать это вы все еще получаете ошибки. Это будет служить вашей цели. Надеюсь, поможет.

+0

Большое спасибо за помощь :) –

+0

проверьте отредактированный ответ, тщательно отредактируйте свой код, скопируйте только что сделанные изменения. – Keshav1234

+0

После выполнения этих изменений вы не должны получать никаких ошибок, пожалуйста, дайте мне знать. – Keshav1234

0

Я думаю, что ваш макет не завышен, я предлагаю вам добавить notetext EditText в layout.xml layout. Таким образом, вы можете напрямую раздувать этот макет.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" android:layout_height="match_parent" 
android:orientation="vertical" 
android:weightSum="1"> 
<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/noteText" 
    android:singleLine="false" 
    android:gravity="top" 
    android:inputType="textImeMultiLine" 
    android:layout_alignParentBottom="true" /> 
<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Change Text Colour" 
    android:id="@+id/textView" 
    android:layout_weight="0.04" 
    android:textStyle="bold" 
    android:textSize="20dp" /> 

<RadioGroup 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:layout_weight="0.04" 
    android:id="@+id/RadioGroup1" 
    android:focusable="false" 
    android:orientation="vertical"> 
    <RadioButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Red" 
     android:id="@+id/rdbRed" /> 
    <RadioButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Blue" 
     android:id="@+id/rdbBlue" /> 
    <RadioButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Orange" 
     android:id="@+id/rdbOrange" /> 
</RadioGroup> 

<Button 
    android:layout_width="98dp" 
    android:layout_height="wrap_content" 
    android:text="Save" 
    android:id="@+id/btn_Save" 
    android:layout_gravity="center_horizontal" 
    android:layout_weight="0.04" /> 

Вам нужно настроить этот макет в соответствии с вашими потребностями.Я не знаю, какую структуру вы хотите отобразить. Но сначала сделайте изменения, а затем выполните корректировки. И удалите эту строку.

LayoutInflater.from(getApplication()).inflate(R.layout.settings, null); 
+0

, но EditText на самом деле находится в NoteEditor, я не могу переместить его в настройки –

+0

Это другое действие, если не тогда, как вы покажете, что noteEditor в текущей активности. – Codelord

Смежные вопросы