Autore Topic: Errore con fragment  (Letto 331 volte)

Offline ivan88go

  • Nuovo arrivato
  • *
  • Post: 2
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Htc one s
  • Sistema operativo:
    Windows 7
Errore con fragment
« il: 26 Luglio 2014, 20:15:05 CEST »
0
Ciao ragazzi sono alle prese con la realizzazione di un progetto basato su google wallet per l'università.
non ho capito bene l'entità dell'errore quindi vi posto il codice ed il log cat e spero possiate aiutarmi.. Comunque vada grazie in anticipo a tutti

Activity che richiama fragment
Codice (Java): [Seleziona]
public class Carrello extends ShopFragment {
       

       
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.checkout);
               
               
               
               
        }
       
        @Override
    protected void onNewIntent(Intent intent) {
        if (intent.hasExtra(WalletConstants.EXTRA_ERROR_CODE)) {
            int errorCode = intent.getIntExtra(WalletConstants.EXTRA_ERROR_CODE, 0);

            CheckoutFragment fragment =
                    (CheckoutFragment) getSupportFragmentManager().findFragmentById(R.id.frag);
            fragment.cartobj((ItemInfo) intent.getSerializableExtra("cart"));
            fragment.setErrorCode(errorCode);
           
        }
    }

}

carrello.xml
Codice (XML): [Seleziona]
<?xml version="1.0" encoding="utf-8"?>
   
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/frag"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:name="com.example.storeapp.CheckoutFragment"/>

logcat
Codice: [Seleziona]

07-26 20:11:25.994: E/AndroidRuntime(21747): FATAL EXCEPTION: main
07-26 20:11:25.994: E/AndroidRuntime(21747): Process: com.example.storeapp, PID: 21747
07-26 20:11:25.994: E/AndroidRuntime(21747): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.storeapp/com.example.storeapp.Carrello}: android.view.InflateException: Binary XML file line #3: Error inflating class fragment
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.app.ActivityThread.access$800(ActivityThread.java:139)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.os.Handler.dispatchMessage(Handler.java:102)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.os.Looper.loop(Looper.java:136)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.app.ActivityThread.main(ActivityThread.java:5086)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at java.lang.reflect.Method.invokeNative(Native Method)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at java.lang.reflect.Method.invoke(Method.java:515)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at dalvik.system.NativeStart.main(Native Method)
07-26 20:11:25.994: E/AndroidRuntime(21747): Caused by: android.view.InflateException: Binary XML file line #3: Error inflating class fragment
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.app.Activity.setContentView(Activity.java:1937)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at com.example.storeapp.Carrello.onCreate(Carrello.java:19)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.app.Activity.performCreate(Activity.java:5248)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
07-26 20:11:25.994: E/AndroidRuntime(21747):         ... 11 more
07-26 20:11:25.994: E/AndroidRuntime(21747): Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.example.storeapp.Shopapplication
07-26 20:11:25.994: E/AndroidRuntime(21747):         at com.example.storeapp.ShopWalletFragment.getApplication(ShopWalletFragment.java:168)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at com.example.storeapp.ShopWalletFragment.onCreate(ShopWalletFragment.java:97)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at com.example.storeapp.CheckoutFragment.onCreate(CheckoutFragment.java:49)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.support.v4.app.Fragment.performCreate(Fragment.java:1477)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1093)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1195)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291)
07-26 20:11:25.994: E/AndroidRuntime(21747):         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
07-26 20:11:25.994: E/AndroidRuntime(21747):         ... 20 more


L'eccezione viene lanciata non appena clicco su un button che richiama la activity postata sopra. se serve posso postare la classe fragment che richiama ma il problema penso sia in qualcosa che non va in questo passaggio..

Offline ivan88go

  • Nuovo arrivato
  • *
  • Post: 2
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Htc one s
  • Sistema operativo:
    Windows 7
Re:Errore con fragment
« Risposta #1 il: 28 Luglio 2014, 01:09:17 CEST »
0
Tutto risolto