Forum » Programiranje » [android] crash
[android] crash

messi ::
Mi prosim lahko kdo razloži tile napake, zakaj se mi aplikacija crasha, sicer se opravičujem ker je koda tako dolga ampak ne morem pomagat.. Hvala.
09-04 11:44:43.798: D/AndroidRuntime(2235): Shutting down VM
09-04 11:44:43.798: W/dalvikvm(2235): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
09-04 11:44:45.248: E/AndroidRuntime(2235): FATAL EXCEPTION: main
09-04 11:44:45.248: E/AndroidRuntime(2235): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pii/com.example.pii.Draw}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.os.Handler.dispatchMessage(Handler.java:99)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.os.Looper.loop(Looper.java:137)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-04 11:44:45.248: E/AndroidRuntime(2235): at java.lang.reflect.Method.invokeNative(Native Method)
09-04 11:44:45.248: E/AndroidRuntime(2235): at java.lang.reflect.Method.invoke(Method.java:511)
09-04 11:44:45.248: E/AndroidRuntime(2235): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-04 11:44:45.248: E/AndroidRuntime(2235): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-04 11:44:45.248: E/AndroidRuntime(2235): at dalvik.system.NativeStart.main(Native Method)
09-04 11:44:45.248: E/AndroidRuntime(2235): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
09-04 11:44:45.248: E/AndroidRuntime(2235): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:215)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.Activity.requestWindowFeature(Activity.java:3225)
09-04 11:44:45.248: E/AndroidRuntime(2235): at com.example.pii.Draw.onCreate(Draw.java:71)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.Activity.performCreate(Activity.java:5008)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
09-04 11:44:45.248: E/AndroidRuntime(2235): ... 11 more
Koda aplikacije:
in še clas..
09-04 11:44:43.798: D/AndroidRuntime(2235): Shutting down VM
09-04 11:44:43.798: W/dalvikvm(2235): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
09-04 11:44:45.248: E/AndroidRuntime(2235): FATAL EXCEPTION: main
09-04 11:44:45.248: E/AndroidRuntime(2235): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pii/com.example.pii.Draw}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.os.Handler.dispatchMessage(Handler.java:99)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.os.Looper.loop(Looper.java:137)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-04 11:44:45.248: E/AndroidRuntime(2235): at java.lang.reflect.Method.invokeNative(Native Method)
09-04 11:44:45.248: E/AndroidRuntime(2235): at java.lang.reflect.Method.invoke(Method.java:511)
09-04 11:44:45.248: E/AndroidRuntime(2235): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-04 11:44:45.248: E/AndroidRuntime(2235): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-04 11:44:45.248: E/AndroidRuntime(2235): at dalvik.system.NativeStart.main(Native Method)
09-04 11:44:45.248: E/AndroidRuntime(2235): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
09-04 11:44:45.248: E/AndroidRuntime(2235): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:215)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.Activity.requestWindowFeature(Activity.java:3225)
09-04 11:44:45.248: E/AndroidRuntime(2235): at com.example.pii.Draw.onCreate(Draw.java:71)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.Activity.performCreate(Activity.java:5008)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
09-04 11:44:45.248: E/AndroidRuntime(2235): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
09-04 11:44:45.248: E/AndroidRuntime(2235): ... 11 more
Koda aplikacije:
package com.example.pii;
import android.app.Activity;
import android.view.WindowManager.LayoutParams;
import android.content.ContentResolver;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings.SettingNotFoundException;
import android.provider.Settings.System;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.Toast;
public class Draw extends Activity {
SeekBar bar;
static float discrete=0;
float start=0;
float end=100;
float start_pos=0;
int start_position=0;
//UI objects//
//the seek bar variable
private SeekBar brightbar;
//a variable to store the system brightness
private int brightness;
//the content resolver used as a handle to the system's settings
private ContentResolver cResolver;
//a window object, that will store a reference to the current window
private Window window;
/** Menu ID for the command to clear the window. */
private static final int CLEAR_ID = Menu.FIRST;
/** Menu ID for the command to toggle fading. */
private static final int SAMPLES_ID = Menu.FIRST+1;
/** Menu ID for about **/
private static final int ABOUT_ID = Menu.FIRST+2;
/** The view responsible for drawing the window. */
TesterView mView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set full screen view
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Create and attach the view that is responsible for painting.
mView = new TesterView(this, null, 0);
setContentView(mView);
mView.requestFocus();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setContent(R.id.tab1);
spec1.setIndicator("Tab 1",getResources().getDrawable(R.drawable.set));
TabSpec spec2=tabHost.newTabSpec("Tab 2");
spec2.setIndicator("Tab 2",getResources().getDrawable(R.drawable.set));
spec2.setContent(R.id.tab2);
TabSpec spec3=tabHost.newTabSpec("Tab 3");
spec3.setIndicator("Tab 3",getResources().getDrawable(R.drawable.set));
spec3.setContent(R.id.tab3);
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
Button knof;
knof=(Button)findViewById(R.id.button1);
knof.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ColorPickerDialog aa;
//new ColorPickerDialog(this, this, DROIDS_COLOR_KEY, a.getInt(DROIDS_COLOR_KEY, DROIDS_COLOR_DEFAULT), DROIDS_COLOR_DEFAULT).show();
// ((PreferenceScreen)this.findPreference(SETTINGS_KEY)).getEditor().putInt(key, color).commit();
aa = new ColorPickerDialog(null,null,"",0,0);
setContentView(R.layout.io);
// aa.requestFocus();
} });
//začetek sekkbara
start=0; //you need to give starting value of SeekBar
end=10; //you need to give end value of SeekBar
start_pos=5; //you need to give starting position value of SeekBar
start_position=(int) (((start_pos-start)/(end-start))*10);
discrete=start_pos;
SeekBar seek=(SeekBar) findViewById(R.id.seekBar1);
seek.setProgress(start_position);
seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "discrete = "+String.valueOf(discrete), Toast.LENGTH_SHORT).show();
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// TODO Auto-generated method stub
// To convert it as discrete value
float temp=progress;
float dis=end-start;
discrete=(start+((temp/10)*dis));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});
//konec seek bara za velikost ..
// start bright
//get the seek bar from main.xml file
brightbar = (SeekBar) findViewById(R.id.sb_brightbar);
//get the content resolver
cResolver = getContentResolver();
//get the current window
window = getWindow();
//seek bar settings//
//sets the range between 0 and 255
brightbar.setMax(255);
//set the seek bar progress to 1
brightbar.setKeyProgressIncrement(1);
try
{
//get the current system brightness
brightness = System.getInt(cResolver, System.SCREEN_BRIGHTNESS);
}
catch (SettingNotFoundException e)
{
//throw an error case it couldn't be retrieved
Log.e("Error", "Cannot access system brightness");
e.printStackTrace();
}
//sets the progress of the seek bar based on the system's brightness
brightbar.setProgress(brightness);
//register OnSeekBarChangeListener, so it can actually change values
brightbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
//set the system brightness using the brightness variable value
System.putInt(cResolver, System.SCREEN_BRIGHTNESS, brightness);
//preview brightness changes at this window
//get the current window attributes
LayoutParams layoutpars = window.getAttributes();
//set the brightness of this window
layoutpars.screenBrightness = brightness / (float)255;
//apply attribute changes to this window
window.setAttributes(layoutpars);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
//sets the minimal brightness level
//if seek bar is 20 or any value below
if(progress<=20)
{
//set the brightness to 20
brightness=20;
}
else //brightness is greater than 20
{
//sets brightness variable based on the progress bar
brightness = progress;
}
}
});
//zaključek bright
super.onCreate(savedInstanceState);
}// zaključuje on create
public static float getState() {
// TODO Auto-generated method stub
return discrete;
}
@Override public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, CLEAR_ID, 0, "Clear");
menu.add(0, SAMPLES_ID, 0, "Samples").setCheckable(true);
menu.add(0, ABOUT_ID, 0, "Version "+this.getString(R.string.app_name)); /* idea from http://www.connorgarvey.com/blog/?p=9 */
return super.onCreateOptionsMenu(menu);
}
@Override public boolean onPrepareOptionsMenu(Menu menu) {
// menu.findItem(SAMPLES_ID).setChecked(mSamples);
return super.onPrepareOptionsMenu(menu);
}
@Override public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case CLEAR_ID:
mView.clear();
return true;
case SAMPLES_ID:
mView.bShowSamples = !mView.bShowSamples;
return true;
case ABOUT_ID:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override protected void onResume() {
super.onResume();
// If fading mode is enabled, then as long as we are resumed we want
// to run pulse to fade the contents.
}
@Override protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Save away the fading state to restore if needed later. Note that
// we do not currently save the contents of the display.
}
@Override protected void onPause() {
super.onPause();
// Make sure to never run the fading pulse while we are paused or
// stopped.
}
private Handler mHandler = new Handler() {
@Override public void handleMessage(Message msg) {
switch (msg.what) {
// Upon receiving the fade pulse, we have the view perform a
// fade and then enqueue a new message to pulse at the desired
// next time.
default:
super.handleMessage(msg);
}
}
};
}
in še clas..
package com.example.pii;
import java.util.ArrayList;
import java.util.List;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
public class TesterView extends View {
private static final int MAXFINGERS = 20; // count the toes too!
private Bitmap mBitmap;
private Canvas mCanvas;
private final Rect mRect = new Rect();
private final Paint mPaint;
private float mCurX;
private float mCurY;
private float[] mPrevX = new float[MAXFINGERS]; // previous values of x,y to draw line
private float[] mPrevY = new float[MAXFINGERS];
public boolean bShowSamples = true;
public TesterView(Context c, AttributeSet attrs, int defStyle) {
super(c,attrs,defStyle);
setFocusable(true);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setARGB(255, 255, 255, 255);
}
public TesterView(Context c, AttributeSet attrs) {
this(c, attrs, 0);
}
public TesterView(Context c) {
this(c, null, 0);
}
/* if clear command under App's view Menu is used */
public void clear() {
if (mCanvas != null) {
mPaint.setARGB(0xff, 255, 255, 255);
mCanvas.drawPaint(mPaint);
invalidate();
}
}
@Override protected void onSizeChanged(int w, int h, int oldw,
int oldh) {
int curW = mBitmap != null ? mBitmap.getWidth() : 0;
int curH = mBitmap != null ? mBitmap.getHeight() : 0;
if (curW >= w && curH >= h) {
return;
}
if (curW < w) curW = w;
if (curH < h) curH = h;
Bitmap newBitmap = Bitmap.createBitmap(curW, curH,
Bitmap.Config.RGB_565);
newBitmap.eraseColor(Color.WHITE); /* screen goes white */
Canvas newCanvas = new Canvas();
newCanvas.setBitmap(newBitmap);
if (mBitmap != null) {
newCanvas.drawBitmap(mBitmap, 0, 0, null);
}
mBitmap = newBitmap;
mCanvas = newCanvas;
/* initialize previous finger locations so we know later they need to be filled for the first time */
for (int finger=0; finger<MAXFINGERS; finger++){
mPrevX[finger]=-1;
mPrevY[finger]=-1;
}
}
@Override protected void onDraw(Canvas canvas) {
if (mBitmap != null) {
canvas.drawBitmap(mBitmap, 0, 0, null);
}
}
@Override public boolean onTouchEvent(MotionEvent event) {
int action = event.getActionMasked();
int numPtrs;
switch (action) {
case MotionEvent.ACTION_DOWN: /* primary pointer */
case MotionEvent.ACTION_POINTER_DOWN: /* any subsequent pointer */
numPtrs = event.getPointerCount();
for (int finger = 0; finger < numPtrs; finger++) {
mPrevX[finger] = mPrevY[finger] = -1;
}
break;
case MotionEvent.ACTION_MOVE: /* any number of pointers move */
int N = event.getHistorySize();
numPtrs = event.getPointerCount();
for (int histndx = 0; histndx < N; histndx++) {
for (int finger = 0; finger < numPtrs; finger++) {
mCurX = event.getHistoricalX(finger, histndx);
mCurY = event.getHistoricalY(finger, histndx);
drawPoint(mCurX, mCurY,
event.getHistoricalPressure(finger, histndx),
event.getHistoricalSize(finger, histndx), finger);
}
}
for (int finger = 0; finger < numPtrs; finger++) {
mCurX = event.getX(finger);
mCurY = event.getY(finger);
drawPoint(mCurX, mCurY, event.getPressure(finger), event.getSize(finger),finger);
}
break;
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_UP: /* all pointers are up */
case MotionEvent.ACTION_CANCEL:
for (int finger=0; finger<MAXFINGERS; finger++){
mPrevX[finger]=-1;
mPrevY[finger]=-1;
}
break;
}
return true;
}
private void drawLine(int finger) {
mPaint.setARGB(255,0,0,255); /* blue */
mCanvas.drawLine(mPrevX[finger],mPrevY[finger],mCurX,mCurY,mPaint);
}
private void drawPoint(float x, float y, float pressure, float width, int finger) {
//Log.i("TouchPaint", "Drawing: " + x + "x" + y + " p="
// + pressure + " width=" + width);
int lowX,lowY,highX,highY;
if (mBitmap != null) {
float radius = (float) 2.0;
mPaint.setARGB(255,255,0,0);
if (bShowSamples)
mCanvas.drawCircle(x, y, radius, mPaint); // current point
if ((mPrevX[finger]==-1 && mPrevY[finger]==-1)) { /* we don't need to draw a line */
mPrevX[finger] = x;
mPrevY[finger] = y;
mRect.set((int) (x - 3*radius), (int) (y - 3*radius),
(int) (x + 3*radius), (int) (y + 3*radius));
} else {
/* we do need to draw line as we have a valid previous location */
drawLine(finger);
if (mPrevX[finger] <= mCurX){
lowX = (int) (mPrevX[finger] - 3*radius);
highX = (int) (mCurX + 3*radius);
} else {
lowX = (int) (mCurX - 3*radius);
highX = (int) (mPrevX[finger] + 3*radius);
}
if (mPrevY[finger] <= mCurY){
lowY = (int) (mPrevY[finger] - 3*radius);
highY = (int) (mCurY + 3*radius);
} else {
lowY = (int) (mCurY - 3*radius);
highY = (int) (mPrevY[finger] + 3*radius);
}
mRect.set(lowX,lowY,highX,highY);
mPrevX[finger] = mCurX;
mPrevY[finger] = mCurY;
}
invalidate(mRect);
}
}
}

Dejcc ::
requestFeature() must be called before adding content
v 5. vrstici ti piše napako. Popravi metodo onCreate
v 5. vrstici ti piše napako. Popravi metodo onCreate

pzagor2 ::
V Activity-ju Draw v vrstici 71 kličeš "requestWindowFeature(Window.FEATURE_NO_TITLE);" za setContentView(mView); kar ni dovoljeno. Pa če prav vidim maš podvojeno 60 in 71 vrstico + še nakaj drugih vrstic.

messi ::
Hvala za pomoč sicer je bilo napaka v xml kodi
<com.example.pii.TesterView v tem ;)
Je bil star ime. Drugače me pa zanima je tale programeranje praviln in če so poiskane prave rešitve, ali je bolj špageti. In če je slab če ima kdo kako izboljšavo v mislih mi naj porsim pove...Hvala, vsem za pomoč 
messi ::
Moogoče še to sedaj sem zamenjal setcontientview(R.layout.prvastran.xml), pa kar ne dela več clear in menjave vzorcev ;( prej je bilo setcontientview(mView)

messi ::
Da mogoče bolje razložim dodajal sem tab, spacebare in še gumbe ki sem jih postavil na drugo stran pri tem sem pa ogromno stvari pomeš, ker sedaj setcontientview ni več z mView ampak je z prvastran.xml
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | Android - ZačetnikOddelek: Programiranje | 1812 (1137) | hurlimannxt |
» | Programiranje problem androidOddelek: Programiranje | 1195 (960) | g333kk |
» | [Android] Aplikacija se zrušiOddelek: Programiranje | 835 (672) | g333kk |
» | android črtaOddelek: Programiranje | 2444 (1715) | g333kk |
» | [android] vstavljanje slikeOddelek: Programiranje | 1271 (1168) | messi |