Fragment FragmentBasic.zip null pointer TextView article
Example have error code:
//developer.android.com/training/basics/fragments/creating.html
Try to change ArticleFragment.java
//developer.android.com/training/basics/fragments/creating.html
Try to change ArticleFragment.java
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.fragments;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class ArticleFragment extends Fragment {
final static String ARG_POSITION = "position";
int mCurrentPosition = -1;
TextView articleText;
@Override
// public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Bundle savedInstanceState) {
//
// // If activity recreated (such as from screen rotate), restore
// // the previous article selection set by onSaveInstanceState().
// // This is primarily necessary when in the two-pane layout.
// if (savedInstanceState != null) {
// mCurrentPosition = savedInstanceState.getInt(ARG_POSITION);
// }
//
// // Inflate the layout for this fragment
// return inflater.inflate(R.layout.article_view, container, false);
// }
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// If activity recreated (such as from screen rotate), restore
// the previous article selection set by onSaveInstanceState().
// This is primarily necessary when in the two-pane layout.
if (savedInstanceState != null) {
mCurrentPosition = savedInstanceState.getInt(ARG_POSITION);
}
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.article_view, container, false);
articleText = (TextView) rootView.findViewById(R.id.article);
return rootView;
}
@Override
public void onStart() {
super.onStart();
// During startup, check if there are arguments passed to the fragment.
// onStart is a good place to do this because the layout has already been
// applied to the fragment at this point so we can safely call the method
// below that sets the article text.
Bundle args = getArguments();
if (args != null) {
// Set article based on argument passed in
updateArticleView(args.getInt(ARG_POSITION));
} else if (mCurrentPosition != -1) {
// Set article based on saved instance state defined during onCreateView
updateArticleView(mCurrentPosition);
}
}
public void updateArticleView(int position) {
//TextView article = (TextView) getActivity().findViewById(R.id.article); //Error: article=null.
if (articleText != null)
articleText.setText(Ipsum.Articles[position]);
mCurrentPosition = position;
}
/* ERROR public void updateArticleView(int position) {
TextView article = (TextView) getActivity().findViewById(R.id.article);
article.setText(Ipsum.Articles[position]);
mCurrentPosition = position;
}*/
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Save the current article selection in case we need to recreate the fragment
outState.putInt(ARG_POSITION, mCurrentPosition);
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
Motorola Droid X cena od 3 000 KCZ Kč (únor.2012)
Spokojenost uživatelů nadprůměrná.
Motorola Droid X je chytrý telefon s operačním systémem Android.
Motorola Droid X je (22.února2012) 8. nejpoužívanějším chytrým telefonem u programu Sky Map viz tabulka.
Android 2.1
Display 854 x 480 pixelů
8 megapixel fotoaparát dual LED flash
720p HD video recording
Music and Video player
8 GB paměť
rozšíření paměti 32 GB
WiFi/DLNA
TI OMAP3630 processor – 1GHz
4.3-inch large display
Motorola Droid X photo pic image
Zdroj obrázku: wikipedia
Spokojenost uživatelů nadprůměrná.
Motorola Droid X je chytrý telefon s operačním systémem Android.
Motorola Droid X je (22.února2012) 8. nejpoužívanějším chytrým telefonem u programu Sky Map viz tabulka.
Android 2.1
Display 854 x 480 pixelů
8 megapixel fotoaparát dual LED flash
720p HD video recording
Music and Video player
8 GB paměť
rozšíření paměti 32 GB
WiFi/DLNA
TI OMAP3630 processor – 1GHz
4.3-inch large display
Motorola Droid X photo pic image
Zdroj obrázku: wikipedia
Log.e println needs a message error.
E/AndroidRuntime(330): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{b.paint/b.paint.MainActivity}: java.lang.NullPointerException: println needs a message
Try this code:
E/AndroidRuntime(330): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{b.paint/b.paint.MainActivity}: java.lang.NullPointerException: println needs a message
Try this code:
// Error
String s = null;
Log.e("bla", s); // !!! error Log.e println needs a message error.
// OK
String s = null;
Log.e("bla", s+""); // OK
Eclipse.
If install on device signed with proguard *.apk package and try to reinstall it by only signed package get error in parsing the package.
Uninstall the first application with bigger size from device and try install signed package which has a smaller size. Delete from download list previous downloaded *.apk.
This problem occurs when that your downloaded apk file size is less than the
size of the original apk.
If install on device signed with proguard *.apk package and try to reinstall it by only signed package get error in parsing the package.
Uninstall the first application with bigger size from device and try install signed package which has a smaller size. Delete from download list previous downloaded *.apk.
This problem occurs when that your downloaded apk file size is less than the
size of the original apk.
Open your workspace folder and subfolder .metadata:
C:\Users\workspace\.metadata\
Delete .lock file
C:\Users\workspace\.metadata\
Delete .lock file
Set, get string , array of array of strings, Java example code
public final static String[][]_arArOfString_1 = {
new String[] {"bla","bla","hello world!"},
new String[] {},
new String[] {},
new String[] {},
new String[] {},
new String[] {}
};
String sOut = _arArOfString_1[0][2]; // hello world!
Editace: 2016-02-21 12:26:17
Počet článků v kategorii: 396
Url:fragment-fragmentbasic-zip-null-pointer-textview-article