2016-03-26 8 views
2

私は問題があります。プロジェクトにラジオボタンを追加できません。RadioButtonを置くときAndroid Studioにエラーがあります

私のXMLコード:

<?xml version="1.0" encoding="utf-8"?> 

<RadioButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="New RadioButton" 
    android:id="@+id/radioButton" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="183dp" /> 

私のJavaコード:

public class MainActivity extends Activity { 
RadioButton rb; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
rb = (RadioButton)findViewById(R.id.radioButton); 

} 

}

マイログインチャット:アンドロイドのウィジェットパッケージから

03-26 10:13:10.681 12433-12433/? D/dalvikvm: Late-enabling CheckJNI 
03-26 10:13:10.777 12433-12433/? D/AndroidRuntime: Shutting down VM 
03-26 10:13:10.777 12433-12433/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa6249288) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime: FATAL EXCEPTION: main 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.wesley.radiobuttonuygulama/com.example.wesley.radiobuttonuygulama.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class android.widget.RadioButton 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread.access$600(ActivityThread.java:130) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.os.Handler.dispatchMessage(Handler.java:99) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.os.Looper.loop(Looper.java:137) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread.main(ActivityThread.java:4745) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at java.lang.reflect.Method.invokeNative(Native Method) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Method.java:511) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at dalvik.system.NativeStart.main(Native Method) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.widget.RadioButton 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.view.LayoutInflater.createView(LayoutInflater.java:613) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.Activity.setContentView(Activity.java:1867) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at com.example.wesley.radiobuttonuygulama.MainActivity.onCreate(MainActivity.java:11) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.Activity.performCreate(Activity.java:5008) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread.access$600(ActivityThread.java:130)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.os.Handler.dispatchMessage(Handler.java:99)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.os.Looper.loop(Looper.java:137)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread.main(ActivityThread.java:4745)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at java.lang.reflect.Method.invokeNative(Native Method)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Method.java:511)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at dalvik.system.NativeStart.main(Native Method)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at java.lang.reflect.Constructor.constructNative(Native Method) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.view.LayoutInflater.createView(LayoutInflater.java:587) 
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.Activity.setContentView(Activity.java:1867)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at com.example.wesley.radiobuttonuygulama.MainActivity.onCreate(MainActivity.java:11)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.Activity.performCreate(Activity.java:5008)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread.access$600(ActivityThread.java:130)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.os.Handler.dispatchMessage(Handler.java:99)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.os.Looper.loop(Looper.java:137)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at android.app.ActivityThread.main(ActivityThread.java:4745)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at java.lang.reflect.Method.invokeNative(Native Method)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Method.java:511)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime:  at dalvik.system.NativeStart.main(Native Method)  
03-26 10:13:10.941 12433-12433/com.example.wesley.radiobuttonuygulama E/AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_btn_radio_material.xml from drawable resource ID #0x7f020008 
+0

役立つと思いましたか? – KDeogharkar

+0

レイアウトに囲むことなく、xmlにラジオボタンを置くだけでしたか?あなたは完全なXMLコード – Imdad

+0

私はスクリーンショットを共有 –

答えて

0

インポートラジオボタン:

import android.widget.RadioButton; 
import com.example.wesley.radiobuttonuygulama.R; 

[com.example.wesley.radiobuttonuygulama]アプリケーションのパッケージ名があります

+0

私は同じ問題を試みた。 –

+0

あなたのJavaコードのスクリーンショットを共有 –

+0

http://s30.postimg.org/69muo9o6p/ss2.png –

-1

このコードでは、このコードでは初期化されていますが使用されていないので、これは参考になると思います私は、この例では、あなたのXMLには17行ではありません何

 RadioGroup Class; // declared radio group 
    RadioButton selectclass; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    radioListener(); 
    } 

    public void radioListener(){ 

     Class = (RadioGroup)findViewById(R.id.radioGroup1); 
     select = (Button)findViewById(R.id.submitbut); 

     select.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 

      getSelected = Class.getCheckedRadioButtonId(); 

      selectclass = (RadioButton)findViewById(getSelected); 

       Toast.makeText(MainActivity.this, 
     selectclass.getText().toString(), 
      Toast.LENGTH_SHORT).show(); 

       } 
      }); 

http://androidcoding.in/2016/02/22/android-tutorial-on-radio-button/

+0

さらに情報を追加してください - 壊れたリンクは有効ですが、有効である必要があることを覚えておいてください! – cramopy

+0

リンクが正常に動作しています – pabhishek

+0

リンク**が壊れた場合のサンプルを追加してください。 – cramopy

関連する問題